当前位置: 首页 > news >正文

电子政务系统网站建设的基本过程做网站第一步做什么

电子政务系统网站建设的基本过程,做网站第一步做什么,外汇平台网站开发需求说明,wordpress参数传递的函数行政区划获取 获取2023年的行政区划,并以 编码: 省市区 格式保存为字典方便后续调用 注:网址可能会更新,根据最新的来 # 获取并保存行政区划代码 import requests from lxml import etree import jsondef fetch_html(url):""&quo…

行政区划获取

获取2023年的行政区划,并以 编码: 省市区 格式保存为字典方便后续调用
注:网址可能会更新,根据最新的来

# 获取并保存行政区划代码
import requests
from lxml import etree
import jsondef fetch_html(url):"""获取网页内容"""try:response = requests.get(url)response.raise_for_status()response.encoding = 'utf-8'return response.textexcept requests.RequestException as e:print(f"请求失败: {e}")return Nonedef parse_html(html):"""解析HTML并生成行政区划字典"""if not html:return Nonehtml_tree = etree.HTML(html)rows = html_tree.xpath('//*[text()="行政区划代码"]/../following-sibling::tr')location_dict = {}current_province = ''current_city = ''for row in rows:if not row.xpath('./td[2]/text()'):continuecode = row.xpath('./td[2]/text()')[0].strip()name = row.xpath('./td[3]/text()')[0].replace('*', '').strip()if code.endswith('0000'):  # 省级current_province = namelocation_dict[code] = {'province': current_province, 'city': '', 'district': ''}elif code.endswith('00'):  # 市级current_city = namelocation_dict[code] = {'province': current_province, 'city': current_city, 'district': ''}else:  # 区县级location_dict[code] = {'province': current_province, 'city': current_city, 'district': name}return location_dictdef generate_full_address(location_dict):"""生成完整的地址字符串"""finally_location_dict = {}for code, location in location_dict.items():full_address = f"{location['province']} {location['city']} {location['district']}".strip()finally_location_dict[code] = full_addressreturn finally_location_dictdef save_to_json(data, filename):"""将数据保存为JSON文件"""try:with open(filename, 'w+', encoding='utf-8') as f:json.dump(data, f, ensure_ascii=False, indent=2)print(f"数据已成功保存到 {filename}")except IOError as e:print(f"文件保存失败: {e}")def main():url = 'https://www.mca.gov.cn/mzsj/xzqh/2023/202301xzqh.html'html = fetch_html(url)if html:location_dict = parse_html(html)if location_dict:finally_location_dict = generate_full_address(location_dict)save_to_json(finally_location_dict, 'city_and_code.json')if __name__ == "__main__":main()# 提取编码对应省市区
# with open(r'city_and_code.json', "r", encoding="utf-8") as f:
#     dict_ = json.load(f)
# print(dict_["320507"])
http://www.yayakq.cn/news/389713/

相关文章:

  • 北京南昌网站建设wordpress注册模板
  • 手机网站主页中文网站模板大全
  • 深圳做琴行的公司网站普象工业设计网官网
  • 办公用品网站建设市场定位新品发布会主题大全
  • 贵州做网站找谁免费的png素材网
  • 佳木斯 两学一做 网站网站建设费用如何做账务处理
  • 怎么做淘宝客的网站页游平台网站
  • 服务类网站建设服务公司女生学什么技术最吃香
  • 佛山建站专公众号发布的文章是wordpress
  • 九度网站建设网页设计与网站组建
  • 怎么查看网站收录wps网页制作
  • 网站主页设计收费江浦企业管理咨询服务有限公司
  • 常州网警seo搜索引擎优化总结报告
  • 上海市建设注册管理网站网站注册收入
  • 简述网站开发的5个步骤沈阳网站页面设计公司
  • 潍坊娜娜网站制作寿光 网站建设
  • 绿色网站风格导视设计案例
  • 顺义成都网站建设乌海建设网站
  • 蜘蛛抓取网站模块原理页游源码论坛
  • php网站开发实训报告在线制作图片头像
  • 大型网站建设优化企业网站开发注册个体工商
  • 上海网站建设技术托管seo如何进行优化
  • 网站多级栏目sem和seo的关系
  • 荣耀手机商城官方网站下载网站建设方案标书
  • 做网站空间500m多少钱收费搭建网站
  • 长春能开发网站的公司wordpress任意文件删除
  • 网站网上商城建设方案网站设计过程怎么写
  • 教育网站 网页赏析哈默wordpress上传
  • 朔州公司做网站邯郸建移动网站费用
  • 2015网站设计风格网站建设服务亿企网络