我试图抓住房价以及地址,希望其他相关数据(卧室?)。到目前为止我有以下内容。使用谷歌的元素检查我可以看到有一个元素,但如果我搜索这个,我将无法获得该地址。
有什么想法吗?
import requests
from bs4 import BeautifulSoup
query='http://www.realestate.com.au/buy/with-2-bedrooms-in-epping%2c+nsw+2121/list-1?maxBeds=2&source=refinements'
resp = requests.get(query)
soup = BeautifulSoup(resp.text)
ads=soup.findAll("div", {"id": "searchResultsTbl"})
答案 0 :(得分:2)
如果你需要获得地址,请使用:
import requests
from bs4 import BeautifulSoup
query='http://www.realestate.com.au/buy/with-2-bedrooms-in-epping%2c+nsw+2121/list-1?maxBeds=2&source=refinements'
resp = requests.get(query)
soup = BeautifulSoup(resp.text)
ads = soup.find("div", {"class": "vcard"})
print ads.h2.a.text
输出:
61 Mobbs Lane, Epping, NSW 2121
对于所有地址,请使用:
soup = BeautifulSoup(resp.text)
ads = soup.findAll("div", {"class": "vcard"})
for ad in ads:
print ad.h2.a.text
输出:
61 Mobbs Lane, Epping, NSW 2121
29/3-5 Kandy Avenue, Epping, NSW 2121
5/30 Cambridge Street, Epping, NSW 2121
...
101/239-243 Carlingford Rd, Carlingford, NSW...
65-69 Adderton Road, Telopea, NSW 2117
对于房间,你可以使用这样的东西:
rooms = soup.findAll("li", {"class":"first"})
for room in rooms:
if room.span:
print room.span.text