python 房价

from selenium import webdriver
import time
from numpy import *
import pandas as pd


driver = webdriver.Chrome(executable_path='C:\Program Files (x86)\Google\Chrome\Application\chromedriver')
content_list = []
diqu = [1025,1028,1033,1026,1034,1031,1030,1032,1024,1023,1037,1027,1035,1029,1038,1036,]
for di in diqu:
    list_year = [2021,2020,2019,2018,2017,2016,2015,2014,2013,2012,2011,2010,2009,2008]
    for year in list_year:
        item = {}
        driver.get("https://www.58.com/fangjiawang/shi-{}-100/qy-{}/".format(year,di))
        time.sleep(3)
        span = driver.find_elements_by_xpath("//*[@id='main']/div/div[4]/div[3]/div/div/div[1]/div[2]/div[2]/ul/li/a/span")
        qian = [int(x.text[0:-3]) for x in span]
        # print(qian)
        avg = sum(qian)/len(qian)
        item["di"] = di
        time.sleep(0.1)
        item["year"] = year
        time.sleep(0.1)
        item["avg"] = avg
        print(item)
        content_list.append(item)

time.sleep(3)
di = [z1["di"] for z1 in content_list]
year = [z2["year"] for z2 in content_list]
avg = [z3["avg"] for z3 in content_list]
data = pd.DataFrame({'地区': di,'年份': year,'平均房价': avg})
data.to_excel("1.xlsx")
driver.quit()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值