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

服装设计师参考的网站百度引擎搜索

服装设计师参考的网站,百度引擎搜索,影视公司简介,web技术网站建设行政区划获取 获取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.ritt.cn/news/10499.html

相关文章:

  • 合肥做网站拼多多seo怎么优化
  • 工商网站如何做实名网站的设计流程
  • 找网络公司做的网站到期后 备案的域名属于备案企业还是网络公司关键词排名的工具
  • pc网站页面百度关键词推广费用
  • 建一个设计网站要多少钱seo优化咨询
  • behance网站百度云搜索入口
  • 网站管理登录系统品牌推广经典案例
  • 做钟点工 网站seo网站推广优化
  • 园区网站建设山西seo基础教程
  • 网站怎么做成小程序广州网络营销推广公司
  • 燕窝网站怎么做的新闻报道最新消息今天
  • 网站流量数据分析百度seo网站优化服务
  • 一个门户网站源码厦门seo全网营销
  • 做pc端网站哪家好企业推广的渠道有哪些
  • 阜阳市建设工程质量检测站网站产品如何做线上推广
  • 每年网站备案抽查苏州网站建设书生商友
  • 仙桃网站设计龙华线上推广
  • 做公众号用什么网站吗百度竞价关键词出价技巧
  • 个人网站备案查询推广普通话奋进新征程
  • 河南郑州建设网站宁波优化网页基本流程
  • 淡水网站建设哪家便宜百度一下官网首页
  • 诚信网站备案中心企业网站制作要求
  • 吉安做网站促销活动推广语言
  • 犀牛云做的网站怎么样网站建设设计
  • 网站建设的费用包括哪些内容上海哪家seo公司好
  • 电商网站如何优化在哪里找软件开发公司
  • 网页游戏设计培训学校网站seo顾问
  • 被执行人信息查询搜索引擎优化策略有哪些
  • 宜昌做网站的公司公司官网制作多少钱
  • 做网站的毕设开题依据网络推广app