Wind api crawling weather forecast data

'' ' 
Wind api crawling weather forecast data 
target: https: //free-api.heweather.net/s6/weather/forecast key = cc33b9a52d6e48de852477798980b76e & location = CN101090101? 
   Get Chinese city code: https: //a.hecdn.net /download/dev/china-city-list.csv 
  the current 20 cities to check the next day's weather 
'' ' 
Import Requests 
url = " https://a.hecdn.net/download/dev/china-city-list .csv " 
strHTML = requests.get (URL = URL) 
Data = strhtml.text 
DATAl = data.split ( " \ n- " )
 for I in Range (. 3 ): 
    data1.remove (DATAl [0]) 

#Test City: Shijiazhuang, get tomorrow's weather 
# url = 'https://free-api.heweather.net/s6/weather/forecast?key=cc33b9a52d6e48de852477798980b76e&location=CN101090101' 
# strHTML = requests.get (url) 
# dict = strhtml.json () 
# weather_t = [] 
# for Item in dict [ "HeWeather6"] [0] [ 'daily_forecast'] [. 1: 2]: 
#      Weather = { 
#          'city name': dict [ "HeWeather6"] [0] [ 'Basic'] [ 'LOCATION'], 
#          'date': Item [ 'dATE'], 
#          'daytime': Item [ 'cond_txt_d'], 
#          'night': item [ 'cond_txt_n']
#        }
#     weather_t.append(weather)
# print(weather_t)

for item in data1[:20]:
    url = 'https://free-api.heweather.net/s6/weather/forecast?key=cc33b9a52d6e48de852477798980b76e&location='+item[0:11]
    strhtml  = requests.get(url)
    dict=strhtml.json()
    weather_t = []
    for item in dict["HeWeather6"][0]['daily_forecast'][1:2]:
        weather = {
            '城市名':dict["HeWeather6"][0]['basic']['location'],
            '今天日期':dict["HeWeather6"][0]['daily_forecast'][0]['date'],
            'utc':dict["HeWeather6"][0]['daily_forecast'][0]['mr'],
            'loc':dict["HeWeather6 " ] [0] [ ' daily_forecast ' ] [0] [ ' MS ' ],
             ' future date ' : Item [ ' DATE ' ],
             ' day ' : Item [ ' cond_txt_d ' ],
             ' night ' : Item [ ' cond_txt_n ' ] 
           } 
        weather_t.append (Weather) 
    Print (weather_t)

 

Guess you like

Origin www.cnblogs.com/chrysanthemum/p/11470569.html