1 Star 3 Fork 2

wjt/areacode-datav-py

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
area.py 683 Bytes
一键复制 编辑 原始数据 按行查看 历史
wjt 提交于 3年前 . init
# 统计局县级及以上行政区划
import requests
from lxml import html
etree = html.etree
import json
area_url = 'http://www.mca.gov.cn/article/sj/xzqh/2020/20201201.html'
response = requests.get(area_url)
result = etree.HTML(response.text)
areacode_list = result.xpath('//tr/td[2]/text()')
areaname_list = result.xpath('//tr/td[3]/text()')
arr = []
for index, areacode in enumerate(areacode_list):
obj = {
'areacode': areacode,
'areaname': areaname_list[index]
# 'areaname': areaname_list[index+2]
}
arr.append(obj)
# jsonfile = open('area.json', 'w', encoding='utf-8')
# json.dump(arr, jsonfile, indent=2, ensure_ascii=False)
print(arr)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/vijtor/areacode-datav-py.git
git@gitee.com:vijtor/areacode-datav-py.git
vijtor
areacode-datav-py
areacode-datav-py
master

搜索帮助