你是幾乎沒有,地址和價格信息爲的<div class="propName">
<div class="clear property left">
下<a>
元素,你可以找到g_data
更深處,像這樣:
import requests
from bs4 import BeautifulSoup
my_url = 'http://www.landwatch.com/Philippines_land_for_sale/Land'
link=requests.get(my_url)
soup = BeautifulSoup(link.content, 'lxml')
g_data =soup.find_all('div',class_='clear property left')
for item in g_data:
address_price_info = item.find("div",{"class":"propName"}).find('a').text
print(address_price_info)
輸出將是:
Cebu City, Philippines 1185000, PHP
Tagaytay, Philippines $116,000
Quezon City, Philippines $2,837,000
Sta Rosa Laguna, Philippines 15500, PHP
Makati, Philippines $5,947,826
Puerto Princesa City, Philippines $358,813
Carcar, Philippines 35000000, PHP
Lipa City, Philippines $57,750
Makati, Philippines 6400000, PHP
Taytay, Philippines $2,300,000
Taguig, Philippines $504,208
Taguig City, Philippines $13,760
Quezon City, Philippines 58000000, PHP
Cebu City, Philippines 7799030, PHP
Las Pinas, Philippines $468,000
更新:
如果您使用Chrome檢查地址和價格信息,它會告訴你的位置:
<div class="clear property left">
<div class="margintop">
...
<div class="propName"> #Here is the address and price info
<a href="/Cebu-City-Philippines-Land-for-sale/pid/119211639" onclick="WC('119211639', '-1');"> Cebu City, Philippines <BR/> 1185000, PHP</a>
</div>
<div>PAYMENT SCHEMES:\r\rReservation Fee : P20,000 (non refundable)\r\r1. SCHEME 1\rCash - 100% with the following discounts\r* 10% for 7 days payment\r* 8%... </div>
...
</div>
<div class="clear"></div>
</div>
太謝謝你了!Tiny.D還有一個簡單的問題,你是如何找到價格和地址信息在propName的?我甚至看不到這一點。 –
@ M.C檢查更新。 –