爬取高德地图提供的省直辖县列表

一. 爬取高德地图提供的省直辖县列表

Url: 如下

https://lbs.amap.com/faq/webservice/webservice-api/geocoding/43267

1.1 代码

from requests_html import HTMLSession, Element

url = 'https://lbs.amap.com/faq/webservice/webservice-api/geocoding/43267'
se = HTMLSession()

dic = {}
ret = se.request(method='get', url=url)
print(ret.html.find('tbody tr td'))
last_city = None
for x in ret.html.find('tbody tr'):
    y = x.find('td')
    if len(y) == 2:  # 省市区
        last_city = y[0].find('p')[0].text
        if dic.get(last_city):
            dic[last_city].append(y[1].find('p')[0].text)
        else:
            dic[last_city] = [y[1].find('p')[0].text]
    else:
        dic[last_city].append(y[0].find('p')[0].text)
print(dic)
posted @ 2020-09-28 16:27  maoruqiang  阅读(350)  评论(1编辑  收藏  举报