python爬取城市天气数据

//54511代表北京气象编码

def get_data_(url):
resp = requests.get(url)
jsonObj = resp.content.decode(‘gbk’)
yingdong = (jsonObj.split("{")[1:])
datas = yingdong[1:]
output = open(‘2021.txt’, ‘a’, encoding=‘utf-8’)
for data in datas:
sub_datas = data.split("}")[0] # str
output.write(sub_datas + “\n”)
print(sub_datas)

data_1_month = get_data_(‘http://tianqi.2345.com/t/wea_history/js/202101/54511_202101.js’)
data_2_month = get_data_(‘http://tianqi.2345.com/t/wea_history/js/202102/54511_202102.js’)
data_3_month = get_data_(‘http://tianqi.2345.com/t/wea_history/js/202103/54511_202103.js’)
data_4_month = get_data_(‘http://tianqi.2345.com/t/wea_history/js/202104/54511_202104.js’)
data_5_month = get_data_(‘http://tianqi.2345.com/t/wea_history/js/202105/54511_202105.js’)
data_6_month = get_data_(‘http://tianqi.2345.com/t/wea_history/js/202106/54511_202106.js’)
data_7_month = get_data_(‘http://tianqi.2345.com/t/wea_history/js/202107/54511_202107.js’)
data_8_month = get_data_(‘http://tianqi.2345.com/t/wea_history/js/202108/54511_202108.js’)
data_9_month = get_data_(‘http://tianqi.2345.com/t/wea_history/js/202109/54511_202109.js’)
data_10_month = get_data_(‘http://tianqi.2345.com/t/wea_history/js/202110/54511_202110.js’)
data_11_month = get_data_(‘http://tianqi.2345.com/t/wea_history/js/202111/54511_202111.js’)
data_12_month = get_data_(‘http://tianqi.2345.com/t/wea_history/js/202112/54511_202112.js’)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

广隶康

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

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

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

打赏作者

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

抵扣说明:

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

余额充值