五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(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)遵守國家法律
乐至县| 游戏| 辰溪县| 泽州县| 焦作市| 平罗县| 维西| 进贤县| 工布江达县| 北碚区| 太康县| 汤阴县| 卢湾区| 灯塔市| 米林县| 德兴市| 梁河县| 盈江县| 莒南县| 盘锦市| 中阳县| 调兵山市| 梓潼县| 乌兰县| 沧州市| 花莲县| 广水市| 化隆| 长泰县| 墨竹工卡县| 麻城市| 土默特左旗| 磴口县| 玉山县| 肇庆市| 清苑县| 迁西县| 呼伦贝尔市| 栾川县| 鸡东县| 扬中市|