Python爬虫抓取房天下广州楼盘信息失败,求高手帮忙排查问题

最近学习数据挖掘,用 python 写了一个程序,使用 lxml 和 requests 爬 http://gz.newhouse.fang.com/house/s/b91/这个网页,网页爬下来后,用 xpath 挑选数据集。看网页源码可以看到每个楼盘信息的数据分段都是在标签"<div class=clearfix>“里,但是 python 中用 xpath(’//div[@class=“clearfix”]’)语句,却只返回空表。请各位帮忙看看,是哪里错了?



for index in range(28):
url = ‘http://gz.newhouse.fang.com/house/s/b9{}’.format(index)
con=con+requests.get(url).content
sel = html.fromstring(con)
print(“Read!”)

print(“Writting”,end=”")



#获得楼盘信息的数据集合
for i in sel.xpath(’//div[@class=“clearfix”]’):
# 楼盘名称
name = “”.join(i.xpath(‘div[@class=“div class=“house_value clearfix””]/div/a/text()’)).split()
print(name)

print(".",end="")

print(“Done!”)
Python爬虫抓取房天下广州楼盘信息失败,求高手帮忙排查问题


4 回复

问题是你这个代码根本没法运行啊.
con 是啥
html 是啥.
根本没说.
在知乎看到过了, 我专门拷贝下来想运行一下的.


我无法理解你的问题

对不起,我没留意到发帖时候抓屏不全

import requests
import pymysql
from lxml import html

db=pymysql.connect(host=‘localhost’,port=3306,user=‘dbuser’,passwd=‘wilson’,db=‘mydb’,charset=‘utf8’)
cursor = db.cursor()
#ursor.execute("TRUNCATE TABLE gz_newhouse")
#b.commit()
con=b’’

先取 这个 //*[@id=“newhouse_loupai_list”]/ul/li

再循环

回到顶部