/
(2020年8月中华人民共和国县以上行政区划代码)
//article/sj/xzqh/2020/2020/2020092500801.html
# -*- coding: utf-8 -*-
"""
Created on Tue Nov 17 14:02:23 2020@author: 樊纲
"""import requests
from bs4 import BeautifulSoup
import pandas as pd
import reurl='//article/sj/xzqh/2020/202011/202011060901.html'
r(url)
html
soup=BeautifulSoup(html,'html.parser')
table=soup.find('table')
trs=table.find_all('tr')[2:-9]
datas=[]
for tr in trs:data=[]_text().replace('n',''):td=tr.find_all('td')code=tr.find_next('td').find_next('td').get_text()name=tr.find_next('td').find_next('td').find_next('td').get_text()print(code,re.sub("s","",name))data.append(code)data.append(re.sub("s","",name))#正则替换不可见字符datas.append(data)
df=pd.DataFrame(datas[1:],columns=datas[0])
df.to_excel('./data/行政区划代码.xlsx')#保存为Excel文件
本文发布于:2024-02-02 16:49:18,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170686375645129.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |