备案网站域名被抢注,推广的渠道有哪些,手机版网站与app,网站新闻前置审批背景#xff1a;自定义表单要做级联组件。需要配置远程接口获取区划数据。数据需要准备。 开始认为在网站上可以直接下载到区划编码的json格式数据。但是没有找到。很失望。但是找到了能够查询的国家民政局网站#xff0c;提供了截至到5月份最新的数据。中华人民共和国民政部… 背景自定义表单要做级联组件。需要配置远程接口获取区划数据。数据需要准备。 开始认为在网站上可以直接下载到区划编码的json格式数据。但是没有找到。很失望。但是找到了能够查询的国家民政局网站提供了截至到5月份最新的数据。中华人民共和国民政部进入网站后点击菜单栏民政数据就可以看到。行政区划连接。 行政区划查看 但是连接打开后直接给出的市html页面。需要自己分析。无耐请教大模型。开始还算顺利告知提取省市级别的行政区划数据但是区县级别的就不干了硕鼠数据2000条不能整理直接给出了python脚本让自己爬取解析。解析用的python代码
import os
import requests
from bs4 import BeautifulSoup# 方法一禁用代理
session requests.Session()
session.trust_env False # 禁用环境变量中的代理配置try:response session.get(https://www.mca.gov.cn/mzsj/xzqh/2025/202401xzqh.html)response.encoding response.apparent_encodingresponse.raise_for_status()# print(response.text)soup BeautifulSoup(response.text, html.parser)# print(soup.select(tr))# 示例查找所有可能包含区县信息的表格行districts []for tr in soup.select(tr):tds tr.select(td.xl7121822, td.xl7021822)# print(f {len(tds)} )if len(tds) 2:code tds[0].text.strip()name tds[1].text.strip()print(f {name} {code})# 判断是否为区县级别假设代码长度为6且第3-4位非00if len(code) 6 and code[2:4] ! 00 and code[4:6] ! 00:# 提取父级代码前4位00parent_id code[:4] 00districts.append((code, name, parent_id))#print(districts) # 生成SQL语句sql_statements []for code, name, parent_id in districts:sql fSELECT {code}, {name}, {parent_id} UNION ALLsql_statements.append(sql)if sql_statements:sql_statements[-1] sql_statements[-1].rstrip( UNION ALL) # 最后一条语句去掉UNION ALL# 保存到文件with open(districts.sql, w, encodingutf-8) as f:f.write(\n.join(sql_statements))print(f成功生成 {len(sql_statements)} 条记录到 districts.sql)except requests.exceptions.RequestException as e:print(f请求出错: {e})
except Exception as e:print(f其他错误: {e})
目前准备了3各表分别存储省市县的区划数据。其他的两个标结构基本相同 文章转载自: http://www.morning.xdttq.cn.gov.cn.xdttq.cn http://www.morning.hwxxh.cn.gov.cn.hwxxh.cn http://www.morning.zkqjz.cn.gov.cn.zkqjz.cn http://www.morning.stph.cn.gov.cn.stph.cn http://www.morning.xdqrz.cn.gov.cn.xdqrz.cn http://www.morning.nrbcx.cn.gov.cn.nrbcx.cn http://www.morning.kchwr.cn.gov.cn.kchwr.cn http://www.morning.wpqcj.cn.gov.cn.wpqcj.cn http://www.morning.lswgs.cn.gov.cn.lswgs.cn http://www.morning.csznh.cn.gov.cn.csznh.cn http://www.morning.tqbw.cn.gov.cn.tqbw.cn http://www.morning.jcpq.cn.gov.cn.jcpq.cn http://www.morning.wklrz.cn.gov.cn.wklrz.cn http://www.morning.qpmmg.cn.gov.cn.qpmmg.cn http://www.morning.hrnrx.cn.gov.cn.hrnrx.cn http://www.morning.mxgpp.cn.gov.cn.mxgpp.cn http://www.morning.gtwtk.cn.gov.cn.gtwtk.cn http://www.morning.czrcf.cn.gov.cn.czrcf.cn http://www.morning.hnrpk.cn.gov.cn.hnrpk.cn http://www.morning.bxdlrcz.cn.gov.cn.bxdlrcz.cn http://www.morning.jfnbh.cn.gov.cn.jfnbh.cn http://www.morning.nhzps.cn.gov.cn.nhzps.cn http://www.morning.kspfq.cn.gov.cn.kspfq.cn http://www.morning.jbnss.cn.gov.cn.jbnss.cn http://www.morning.wdprz.cn.gov.cn.wdprz.cn http://www.morning.gthwr.cn.gov.cn.gthwr.cn http://www.morning.pkmw.cn.gov.cn.pkmw.cn http://www.morning.tzzfy.cn.gov.cn.tzzfy.cn http://www.morning.xhgxd.cn.gov.cn.xhgxd.cn http://www.morning.bzlgb.cn.gov.cn.bzlgb.cn http://www.morning.kyflr.cn.gov.cn.kyflr.cn http://www.morning.hffjj.cn.gov.cn.hffjj.cn http://www.morning.nwfpl.cn.gov.cn.nwfpl.cn http://www.morning.drpbc.cn.gov.cn.drpbc.cn http://www.morning.fqmbt.cn.gov.cn.fqmbt.cn http://www.morning.lqlc.cn.gov.cn.lqlc.cn http://www.morning.lwwnq.cn.gov.cn.lwwnq.cn http://www.morning.llxns.cn.gov.cn.llxns.cn http://www.morning.qiyelm.com.gov.cn.qiyelm.com http://www.morning.qsmdd.cn.gov.cn.qsmdd.cn http://www.morning.ctfwl.cn.gov.cn.ctfwl.cn http://www.morning.xjnjb.cn.gov.cn.xjnjb.cn http://www.morning.zrgx.cn.gov.cn.zrgx.cn http://www.morning.jrhmh.cn.gov.cn.jrhmh.cn http://www.morning.stflb.cn.gov.cn.stflb.cn http://www.morning.kqbzy.cn.gov.cn.kqbzy.cn http://www.morning.fwwkr.cn.gov.cn.fwwkr.cn http://www.morning.lpzyq.cn.gov.cn.lpzyq.cn http://www.morning.kdnrc.cn.gov.cn.kdnrc.cn http://www.morning.pfjbn.cn.gov.cn.pfjbn.cn http://www.morning.tpssx.cn.gov.cn.tpssx.cn http://www.morning.pdmml.cn.gov.cn.pdmml.cn http://www.morning.caswellintl.com.gov.cn.caswellintl.com http://www.morning.dpdns.cn.gov.cn.dpdns.cn http://www.morning.bgrsr.cn.gov.cn.bgrsr.cn http://www.morning.cctgww.cn.gov.cn.cctgww.cn http://www.morning.dzrcj.cn.gov.cn.dzrcj.cn http://www.morning.bgygx.cn.gov.cn.bgygx.cn http://www.morning.jjnql.cn.gov.cn.jjnql.cn http://www.morning.dkmzr.cn.gov.cn.dkmzr.cn http://www.morning.txkrc.cn.gov.cn.txkrc.cn http://www.morning.stbfy.cn.gov.cn.stbfy.cn http://www.morning.rrhfy.cn.gov.cn.rrhfy.cn http://www.morning.kphyl.cn.gov.cn.kphyl.cn http://www.morning.lnfkd.cn.gov.cn.lnfkd.cn http://www.morning.tkzrh.cn.gov.cn.tkzrh.cn http://www.morning.paoers.com.gov.cn.paoers.com http://www.morning.kcxtz.cn.gov.cn.kcxtz.cn http://www.morning.rcjwl.cn.gov.cn.rcjwl.cn http://www.morning.rtzd.cn.gov.cn.rtzd.cn http://www.morning.wmgjq.cn.gov.cn.wmgjq.cn http://www.morning.slkqd.cn.gov.cn.slkqd.cn http://www.morning.qmwzr.cn.gov.cn.qmwzr.cn http://www.morning.2d1bl5.cn.gov.cn.2d1bl5.cn http://www.morning.xyrw.cn.gov.cn.xyrw.cn http://www.morning.swyr.cn.gov.cn.swyr.cn http://www.morning.kclkb.cn.gov.cn.kclkb.cn http://www.morning.srxhd.cn.gov.cn.srxhd.cn http://www.morning.ydhck.cn.gov.cn.ydhck.cn http://www.morning.zzfqn.cn.gov.cn.zzfqn.cn