高德POI数据获取,以爬取长沙学校POI为例
import requestsimport pandas as pdimport numpy as npimport jsoncity = "长沙"# 这里只是示例,如果你要爬全长沙建议分区爬这样数据更完整,不推荐爬数据量超过1W的,超过1w需要做切片,参看开发文档的多边形搜索keywords = "学校"# 这里tp示例是汽车服务,你需要查询POI类别的文档看你需要的是什么填入...
·
import requests
import pandas as pd
import numpy as np
import json
city = "长沙"
# 这里只是示例,如果你要爬全长沙建议分区爬这样数据更完整,不推荐爬数据量超过1W的,超过1w需要做切片,参看开发文档的多边形搜索
keywords = "学校"
# 这里tp示例是汽车服务,你需要查询POI类别的文档看你需要的是什么填入
tp = "010000"
url = "https://restapi.amap.com/v3/place/text?keywords={}&city={}&type={}&output=json&offset=50&page=1&key=请输入你的key&extensions=all".format(
keywords, city, tp)
r = requests.get(url).text
dt = json.loads(r)
number = int(int(dt['count']) / 50) + 1
df = pd.DataFrame(columns=['id', 'parent', 'childtype', 'name', 'tag', 'type', 'typecode',
'biz_type', 'address', 'location', 'tel', 'postcode', 'website',
'email', 'pcode', 'pname', 'citycode', 'cityname', 'adcode', 'adname',
'importance', 'shopid', 'shopinfo', 'poiweight', 'gridcode', 'distance',
'navi_poiid', 'entr_location', 'business_area', 'exit_location',
'match', 'recommend', 'timestamp', 'alias', 'indoor_map', 'indoor_data',
'groupbuy_num', 'discount_num', 'biz_ext', 'event', 'children',
'photos'])
for i in range(number):
url = "https://restapi.amap.com/v3/place/text?keywords={}&city={}&type={}&output=json&offset=50&page={}&key=b28485decd427836f19831634ebd4b6f&extensions=all".format(
keywords, city, tp, i)
r = requests.get(url).text
dt = json.loads(r)
data = pd.DataFrame(dt['pois'])
df = pd.concat([data, df])
df = df[['name', 'address', 'location']]
location = []
for i in df['location']:
location.append(str(i).split(','))
dt2 = pd.DataFrame(location,columns=['lng','lat'])
df['lng'] = dt2['lng']
df['lat'] = dt2['lat']
df = df[['name', 'address', 'lng','lat']]
df['lat'] = df['lat'].apply(lambda x: x.strip())
df['lat'] = df['lat'].apply(lambda x: float(x))
df['lng'] = df['lng'].apply(lambda x: x.strip())
df['lng'] = df['lng'].apply(lambda x: float(x))
df.to_csv(r'C:/Users/Windows/Desktop/test.csv', encoding='gbk', index=False)
print("finish!")
更多推荐
所有评论(0)