提起高德地图,咱们每一个人都不会陌生,高德地图是一款非常好用的地区服务软件,很多用户在出行的时候都会使用这款软件,日程用来导航,也可以用来打车,一次呼叫多种车型,用户可以在这里获得更好的服务,随时都可以掌握的线上服务。有很多用户都知道这款软件好用,那知道如何用我们python爬取高德地图吗?今天小编就为大家介绍一下。
代码:
import requests import json def weatherlist(url1,url2,headers,proxies): response = requests.get(url=url1, headers=headers, proxies=proxies).content.decode('utf-8') response = json.loads(response) for i in response["data"]["cityByLetter"].values(): for j in i: adcode = j["adcode"] name = j["name"] full_url = url2+adcode response = requests.get(url=full_url, headers=headers, proxies=proxies).content.decode('utf-8') response = json.loads(response) print(response) try: if response["data"]["data"]: for weather in response["data"]["data"]: for weather in weather['forecast_data']: weather_name = weather['weather_name'] temp_min = weather['min_temp'] temp_max = weather['max_temp'] with open('weather_list.txt', 'a', encoding='utf-8') as fp: fp.write("城市:"+name+ " 天气: "+weather_name+" 最高气温: "+ temp_max +" 最低气温: "+temp_min+'n') except: print('空') if __name__ == '__main__': url1 = 'https://www.amap.com/service/cityList' url2 = 'https://www.amap.com/service/weather?adcode=' headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36','cookie':'BIDUPSID=F6BBCD59FE2A646812DB8DAE641A0BE5; PSTM=1573713375; BAIDUID=F6BBCD59FE2A6468D0329C1E2F60212F:FG=1; BD_UPN=12314353; BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; H_PS_PSSID=1452_21098_29568_29221_26350; delPer=0; BD_CK_SAM=1; PSINO=2; H_PS_645EC=50d5uY51q2qJG%2BVlK7rlPmCgY73TcN9qKRz4sPKuBII1GIkIx4QkChitGd4; BDSVRTM=209'} proxies = {'http':'124.113.217.5:9999','https':''} weatherlist(url1,url2,headers,proxies)
高德地图数据广泛、准确、及时,如果小伙伴正在学习爬虫,可以来爬取高德地图练练手哦~更多学习推荐:python学习网。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)