最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

python爬高德地圖的poi數(shù)據(jù)(很好用)

2022-04-19 00:03 作者:千島寒流-日本暖流  | 我要投稿

重點(diǎn):下面代碼中提及的密鑰申請(qǐng)(參考文章):http://t.csdn.cn/NDoYw

下面是代碼:

from urllib.parse import quote
from urllib import request
import json
import xlwt

#TODO 替換為上面申請(qǐng)的密鑰
amap_web_key = '9c73ee36a6501cd518e62954094fc951'
poi_search_url = "http://restapi.amap.com/v3/place/text"
poi_boundary_url = "https://ditu.amap.com/detail/get/detail"
#from transCoordinateSystem import gcj02_to_wgs84

#TODO cityname為需要爬取的POI所屬的城市名,nanning_areas為城市下面的所有區(qū),classes為多個(gè)分類名集合. (中文名或者代碼都可以,代碼詳見高德地圖的POI分類編碼表)
cityname = '北京市'
nanning_areas = ['海淀區(qū)']

classes = ['高中','醫(yī)院','公園','小學(xué)','超市','初中']


# 根據(jù)城市名稱和分類關(guān)鍵字獲取poi數(shù)據(jù)
def getpois(cityname, keywords):
? ?i = 1
? ?poilist = []
? ?while True: ?# 使用while循環(huán)不斷分頁獲取數(shù)據(jù)
? ? ? ?result = getpoi_page(cityname, keywords, i)

? ? ? ?result = json.loads(result) ?# 將字符串轉(zhuǎn)換為json
? ? ? ?if result['count'] == '0':
? ? ? ? ? ?break
? ? ? ?hand(poilist, result)
? ? ? ?i = i + 1
? ?return poilist


# 數(shù)據(jù)寫入excel
def write_to_excel(poilist, cityname, classfield):
? ?# 一個(gè)Workbook對(duì)象,這就相當(dāng)于創(chuàng)建了一個(gè)Excel文件
? ?book = xlwt.Workbook(encoding='utf-8', style_compression=0)
? ?sheet = book.add_sheet(classfield, cell_overwrite_ok=True)

? ?# 第一行(列標(biāo)題)
? ?sheet.write(0, 0, 'x')
? ?sheet.write(0, 1, 'y')
? ?sheet.write(0, 2, 'count')
? ?sheet.write(0, 3, 'name')


? ?for i in range(len(poilist)):
? ? ? ?location = poilist[i]['location']
? ? ? ?name = poilist[i]['name']
? ? ? ?lng = str(location).split(",")[0]
? ? ? ?lat = str(location).split(",")[1]

? ? ? ?'''
? ? ? ?result = gcj02_to_wgs84(float(lng), float(lat))

? ? ? ?lng = result[0]
? ? ? ?lat = result[1]
? ? ? ?'''

? ? ? ?# 每一行寫入
? ? ? ?sheet.write(i + 1, 0, lng)
? ? ? ?sheet.write(i + 1, 1, lat)
? ? ? ?sheet.write(i + 1, 2, 1)
? ? ? ?sheet.write(i + 1, 3, name)



? ?# 最后,將以上操作保存到指定的Excel文件中
? ?book.save(r'' + cityname + "_" + classfield + '.xls')


# 將返回的poi數(shù)據(jù)裝入集合返回
def hand(poilist, result):
? ?# result = json.loads(result) ?# 將字符串轉(zhuǎn)換為json
? ?pois = result['pois']
? ?for i in range(len(pois)):
? ? ? ?poilist.append(pois[i])


# 單頁獲取pois
def getpoi_page(cityname, keywords, page):
? ?req_url = poi_search_url + "?key=" + amap_web_key + '&extensions=all&keywords=' + quote(
? ? ? ?keywords) + '&city=' + quote(cityname) + '&citylimit=true' + '&offset=25' + '&page=' + str(
? ? ? ?page) + '&output=json'
? ?data = ''
? ?with request.urlopen(req_url) as f:
? ? ? ?data = f.read()
? ? ? ?data = data.decode('utf-8')

? ?return data


for clas in classes:
? ?classes_all_pois = []
? ?for area in nanning_areas:
? ? ? ?pois_area = getpois(area, clas)
? ? ? ?print('當(dāng)前城區(qū):' + str(area) + ', 分類:' + str(clas) + ", 總的有" + str(len(pois_area)) + "條數(shù)據(jù)")
? ? ? ?classes_all_pois.extend(pois_area)
? ?print("所有城區(qū)的數(shù)據(jù)匯總,總數(shù)為:" + str(len(classes_all_pois)))

? ?write_to_excel(classes_all_pois, cityname, clas)

? ?print('================分類:' ?+ str(clas) + "寫入成功")

python爬高德地圖的poi數(shù)據(jù)(很好用)的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國家法律
长顺县| 松原市| 湖州市| 临夏市| 会宁县| 武安市| 彭泽县| 海门市| 阳曲县| 安塞县| 河池市| 永德县| 德兴市| 阿坝| 邻水| 平和县| 温宿县| 岳阳县| 正阳县| 新邵县| 政和县| 祁连县| 郴州市| 修水县| 亚东县| 临邑县| 砀山县| 海晏县| 阿合奇县| 深圳市| 颍上县| 通海县| 肃宁县| 鄢陵县| 法库县| 揭东县| 安达市| 沾化县| 禄劝| 苏尼特左旗| 庆元县|