其他分享
首页 > 其他分享> > 3.2 API获取城市天气

3.2 API获取城市天气

作者:互联网

 1 import time
 2 # import pymongo
 3 import requests
 4 
 5 url='https://cdn.heweather.com/china-city-list.txt'
 6 strhtml=requests.get(url)
 7 # strhtml.encoding='utf8'
 8 data=strhtml.text
 9 data1=data.split("\n")
10 
11 for i in range(3):
12         data1.remove(data1[0])
13 
14 for item in data1:
15         
16         url = 'https://free-api.heweather.net/s6/weather/forecast?location='+item[1:13]+'&key=55693978f3b247a99712170f512f1107'
17         strhtml = requests.get(url)
18         strhtml.encoding='utf-8'
19         time.sleep(1)
20         print(strhtml.text)

执行后

 

 红色框起来的内容,还没调好

标签:strhtml,url,encoding,获取,API,3.2,import,requests,data1
来源: https://www.cnblogs.com/lingyishan2020/p/13517229.html