标签:url forecast 爬取 item api dict weather 天气预报 HeWeather6
''' 和风api爬取天气预报数据 目标:https://free-api.heweather.net/s6/weather/forecast?key=cc33b9a52d6e48de852477798980b76e&location=CN101090101 得到中国城市的代码:https://a.hecdn.net/download/dev/china-city-list.csv 目前先查20个城市第二天的天气 ''' import requests url = "https://a.hecdn.net/download/dev/china-city-list.csv" strhtml = requests.get(url=url) data = strhtml.text data1 = data.split("\n") for i in range(3): data1.remove(data1[0]) # 测试城市:石家庄,得到明天的天气情况 # 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 = { # '城市名':dict["HeWeather6"][0]['basic']['location'], # '日期':item['date'], # '白天':item['cond_txt_d'], # '夜间':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'], '明天日期':item['date'], '白天':item['cond_txt_d'], '夜间':item['cond_txt_n'] } weather_t.append(weather) print(weather_t)
标签:url,forecast,爬取,item,api,dict,weather,天气预报,HeWeather6 来源: https://www.cnblogs.com/chrysanthemum/p/11470569.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。