爬取天气(python)

import pandas as pd
import requests
import demjson
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.75 Safari/537.36'}
cook = {"Cookie":'UM_distinctid=168ac0f9119565-044e6209c82f7-57b143a-100200-168ac0f911a588; fingerprint=4263213985; _ga=GA1.2.885880429.1551944653; dj_star_ticket=03a4870f2d42b9699ea2449d8fe96d300001652000; com.xiaoju.ecom.mis.login.sso.cookie.key=A0EfpzXG1TNzgluSddBZiSHrUUoJVLR72GKbu%2F5uUNVzcX6ydZdDwxVx1M11amFRF6chwVSj5Pk6%0A3ValqKhe2J2iDvBhI4B5; omgh5sid=640921997642-1553061738689'}
ym = ['201701','201702','201703','201704','201705','201706','201707','201708','201709','201710','201711','201712','201801','201802','201803','201804','201805','201806','201807','201808','201809','201810','201811','201812','201901','201902','201903']
df = pd.DataFrame()
for i in ym:
    url = "https://tianqi.2345.com/t/wea_history/js/"+i+"/58659_"+i+".js"
    response = requests.get(url, cookies=cook, headers=headers)
    text = response.text
    result = text[len("var weather_str="):len(text)-1:1]
    data = demjson.decode(result)
    for i in range(len(data['tqInfo'])-1):
        df_new = pd.DataFrame(data['tqInfo'][i],index=['a'])
        df = pd.concat([df,df_new],ignore_index=True)
df.to_excel("J:\温州天气数据.xlsx")

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

吴名氏.

你的鼓励是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值