如果您需要获取地址,请使用:
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