最近学习数据挖掘,用 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!")
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!")