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

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

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)
原文地址:https://www.cnblogs.com/maoruqiang/p/13745422.html