python 二手房信息抓取

仿照西瓜视频的教程完成以下二手房信息抓取,并生成柱状图的程序。

 from pyecharts.charts import Bar  其中这一行是根据网上https://cloud.tencent.com/developer/article/1588507文章改写,可能是因为 pyecharts升级所致。

import requests
from lxml import html
import pandas as pd
from pyecharts.charts import Bar

etree = html.etree
resp=requests.get("https://zz.lianjia.com/ershoufang/").content.decode()
#print(resp)
html = etree.HTML(resp)
div_list = html.xpath("//div[@class='info clear']")
#print(div_list)
# i=0
ershoufang=[]
for div in div_list:
    name=div.xpath(".//div[@class='positionInfo']/a/text()")[0]
    unitPrice=div.xpath(".//div[@class='unitPrice']/span/text()")[0].replace("元/平","").replace(",","")
    ershoufang.append([name,unitPrice])
    #print("位置:%s--价格:%s"%(name,unitPrice))
title=['小区','单价']
table=pd.DataFrame(ershoufang,columns=title)
print(table)
chart=Bar()
chart.add_xaxis(list(table["小区"]))
chart.add_yaxis("郑州市二手房价格",list(table["单价"]))
chart.render("./郑州二手房信息.html")
posted @ 2022-01-23 12:52  paoPaoLong_liu  阅读(60)  评论(0)    收藏  举报