Python爬取百度地图AOI的代码
时间: 2023-11-05 07:59:31 浏览: 183
很高兴为您解答问题!下面是Python爬取百度地图AOI的代码,您可以参考一下:
```python
import requests
import json
def get_page(keyword, city, pn):
headers = {
'User-Agent': 'Mozilla / 5.0(Windows NT 10.0;Win64;x64) AppleWebKit / 537.36(KHTML, likeGecko) Chrome / 58.0.3029.110Safari / 537.3',
'Referer': 'http: // map.baidu.com /'
}
url = 'http://map.baidu.com/?qt=s&wd={}&pn={}&rn=10&ie=utf-8&oue=1&fromproduct=jsapi&res=api'.format(keyword, pn)
res = requests.get(url, headers=headers)
decode_res = res.content.decode()
return decode_res
def get_info(keyword, city, pn):
decode_res = json.loads(get_page(keyword, city, pn))
if 'content' not in decode_res['result']:
return ''
for item in decode_res['result']['content']:
if 'name' not in item['std_tag'] or item['std_tag']['name'] != keyword:
continue
for location in item['geo']:
yield location
if __name__ == '__main__':
keyword = '大厦'
city = '北京'
location_list = []
for pn in range(0, 250, 10):
for location in get_info(keyword, city, pn):
location_list.append(location)
print(location_list)
```
希望对您有所帮助!
阅读全文