生成一个在高德上爬取武汉所有中学和小学的poi的Python代码
时间: 2023-02-25 19:58:31 浏览: 258
爬取高德地图poi数据的python脚本
首先,你需要申请高德API Key,然后才能进行POI数据的爬取。下面是一个使用Python爬取武汉所有中学和小学POI的示例代码:
```
import requests
def get_poi(key, types, city):
"""
获取POI数据
"""
url = "https://restapi.amap.com/v3/place/text"
params = {
"key": key,
"keywords": types,
"types": "学校",
"city": city,
"offset": 20,
"page": 1,
"extensions": "all"
}
res = requests.get(url, params=params)
return res.json()
if __name__ == '__main__':
key = "YOUR_API_KEY"
city = "武汉"
types = "中学,小学"
result = get_poi(key, types, city)
print(result)
```
请将 `YOUR_API_KEY` 替换为您的高德API Key。代码中使用了`requests`库,如果您的环境中没有安装该库,请先安装:
```
pip install requests
```
阅读全文