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

服务周到的网站建站做信息发布类网站

服务周到的网站建站,做信息发布类网站,毕设做购物网站容易吗,建立中英文网站行政区划获取 获取2023年的行政区划#xff0c;并以 编码: 省市区 格式保存为字典方便后续调用 注#xff1a;网址可能会更新#xff0c;根据最新的来 # 获取并保存行政区划代码 import requests from lxml import etree import jsondef fetch_html(url):并以 编码: 省市区 格式保存为字典方便后续调用 注网址可能会更新根据最新的来 # 获取并保存行政区划代码 import requests from lxml import etree import jsondef fetch_html(url):获取网页内容try:response requests.get(url)response.raise_for_status()response.encoding utf-8return 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, encodingutf-8) as f:json.dump(data, f, ensure_asciiFalse, indent2)print(f数据已成功保存到 {filename})except IOError as e:print(f文件保存失败: {e})def main():url https://www.mca.gov.cn/mzsj/xzqh/2023/202301xzqh.htmlhtml 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(rcity_and_code.json, r, encodingutf-8) as f: # dict_ json.load(f) # print(dict_[320507])
http://www.hkea.cn/news/14515878/

相关文章:

  • 做调查网站怎样换IP做百度糯米网站的团队
  • 尉氏做网站推广展示类网站有哪些
  • 建设网站的建筑公司商场设计平面图
  • 韩国情侣网站模板wap网站制作开发公司
  • 网站设计标语沧州网站建设推广
  • 魏县网站制作网站设计制作体会
  • 怎么增加网站权重白银市城乡建设局网站
  • 做网站注意哪些淘宝上开网店的流程
  • 签名设计网站一树擎天又一个wordpress站点
  • 全国网站建设公司排行版二维码生成器app下载安卓版
  • 廉政网站建设的意义网站建设 宝安沙井
  • 如何在建设教育协会网站注册考试wordpress找不到对象
  • 济南网站托管运营重庆茶叶网站建设
  • 网站后台更新前台更新不微信企业号
  • e特快做单子的网站搜狗指数
  • 网站建设时间表国内网站欣赏
  • 有个网站可以学做ppt模板雄安 网站建设
  • 模板网站没有源代码wordpress4.2.8 留言本
  • 小朋友做安全教育的网站淮安做网站需要多少钱
  • 襄阳做网站比较有实力的公司自建网站备案通过后怎么做
  • 网站做支付宝和网银接口营销活动策划方案
  • 电商平台正在建设中网站页面提示创客网站建设
  • 中山网站建设公司易网网站多少
  • 网站路径优化怎么做中国机械加工网官方
  • 中能建设集团电子商务网站山西太原百度公司
  • 竞网做的网站怎么样转做海外买手的网站
  • 绿植行业做网站的做照片用的视频模板下载网站好
  • 大力推进网站集约化建设淘宝找做网站
  • 网站访问流程怎么在手机上制作软件
  • 网站 代理 备案 费用手机商城网站建设