from bs4 import BeautifulSoup
import requests
from concurrent.futures import ThreadPoolExecutor, wait, ALL_COMPLETED
base_url = 'https://www.stats.gov.cn/sj/tjbz/tjyqhdmhcxhfdm/2023/'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0'
}
executor = ThreadPoolExecutor(max_workers=40)
def start():
response = requests.get(base_url, headers=headers)
soup = BeautifulSoup(response.content, 'html.parser')
list_a = soup.findAll('tr', class_='provincetr')
shen = []
for item in list_a:
td = item.findAll('td')
for a in td:
b = a.find('a')
shen.append({
'href': b['href'], 'Name': b.text, 'Id': b['href'].replace('.html', '0000'), 'Pid': '1',
'FullName': f'中国,{
b.text}', 'Level': '1', 'shenId': b['href'].replace('.html', ''),
'fileName': '全国行政区划数据'})
# # 通过省找市区
for shenItem in shen:
getCityData(shenItem)
def getCityData(data):
fileName = data['fileName'
2024全国行政区域爬取脚本(含街道)
最新推荐文章于 2025-05-27 09:44:37 发布

最低0.47元/天 解锁文章
2475

被折叠的 条评论
为什么被折叠?



