基本相同的代码在另一个网站爬取并没有问题。
import requests
from bs4 import BeautifulSoup
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.91 Safari/537.36'}
link = 'http://www.ziroom.com/z/nl/d23008618-b18335654.html'
r = requests.get(link, headers = headers)
soup = BeautifulSoup(r.text, 'lxml')
house_list = soup.find_all('li', class_="clearfix")
for house in house_list:
name = soup.find('div', class_='txt').a.text.strip()
price = soup.find('div', class_='priceDetail').p.text.strip()
area = soup.find('div', class_='detail').span.text.strip()
print (name, '\n', price,'\n', area)
为什么爬取出来的信息只有一条?
舒至嘉园1居室-北
¥ 8260 (每月)
69.21 ㎡
舒至嘉园1居室-北
¥ 8260 (每月)
69.21 ㎡
舒至嘉园1居室-北
¥ 8260 (每月)
69.21 ㎡
舒至嘉园1居室-北
¥ 8260 (每月)
69.21 ㎡
舒至嘉园1居室-北
慕的地6079101
慕函数9285021
慕先生4543078
颜鸿羽
相关分类