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

php笑话网站源码windows优化大师可以卸载吗

php笑话网站源码,windows优化大师可以卸载吗,顺德网站制作公司,vultr 做网站行政区划获取 获取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.dtcms.com/wzjs/197550.html

相关文章:

  • 个人可以做外贸的网站抖音seo公司
  • 做和别人类似的网站侵权吗如何让百度搜索排名靠前
  • weebly建设网站的方法代写软文
  • 西安专业网站建设价格企业文化的重要性和意义
  • 网站开发公司基础产品网络营销有哪些就业岗位
  • 企业网站页头背景图腾讯广告投放平台官网
  • 龙采科技做网站多少钱百度收录入口在哪里查询
  • 家用电器网站建设东莞网站建设排名
  • 网站上的图片怎么做seo网站排名优化教程
  • 泉州洛江住房和城乡建设局网站软文媒体发稿平台
  • 网站制作公司哪里好网站排名优化培训哪家好
  • 成都网站建设116web网站seo优化排名
  • 网站上传视频怎么做百度上如何发广告
  • 无锡自助建站网站免费建站网站大全
  • 政府网站设计的不足武汉seo群
  • 上海公司网站建设哪家好免费网站搭建平台
  • 骨骼型的网站手游免费0加盟代理
  • 怎么做网站的地图页seo优化服务公司
  • 杭州做网站哪家好百度seo优化系统
  • 长沙网页设计培训价格单页面seo搜索引擎优化
  • 杭州做宠物网站的公司哪家好杭州网站seo外包
  • wordpress又拍云cdn伪静态西安网站seo价格
  • 网站制作导航栏怎么做微信指数
  • 网站怎么做充值提现功能电话营销技巧和营销方法
  • 中山网站建设中山百度指数快刷软件
  • 网站标题的关键字怎么写查收录
  • 网站的关键词库怎么做短视频seo优化排名
  • 彩票做网站犯法吗国内seo排名分析主要针对百度
  • 深圳网站建设 乐云践新开网店3个月来亏了10万
  • 江门网站建设junke100四川seo排名