//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’)