
首先要下载第三方库
pip install pandas
pip install requests
pip install urllib3
爬虫之表格的提取源代码
import pandas as pd
import requests
import urllib3
urllib3.disable_warnings()
#网址
url = "http://www.stats.gov.cn/ztjc/zdtjgz/zgrkpc/dqcrkpc/ggl/202105/t20210519_1817699.html"
response = requests.get(url, verify=False)
response.encoding = response.apparent_encoding
html = response.text
tb = pd.read_html(html, header=0)[0]
#最后生成的csv文件
tb.to_csv("biaoge.csv")
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)