批量提取网页表格内容至excel文件

问题背景

将网页的表格内容(5237个股票信息)复制粘贴到excel文件中

网址:A股上市公司名单-A股上市公司名录-A股上市公司大全-商业计划书-可研报告-中商产业研究院数据库-中商情报网

实现代码

python 复制代码
# 导入包
import pandas as pd
import time

# 创建空列表
df_list = []

# 循环读取并拼接网页表格
for i in range(5):
    df = pd.read_html(f'https://s.askci.com/stock/a/0-0?reportTime=2024-03-31&pageNum={i+1}#QueryCondition')
    # 将df拼接到列表中
    df_list.append(df[3])
    # 每次循环休息1秒钟
    time.sleep(1)

# 拼接所有表
all_df = pd.concat(df_list, ignore_index=True)
print(all_df)

# 写入 Excel
all_df.to_excel('./爽解决.xlsx')

实现效果

相关推荐
wtsolutions3 小时前
JSON to Excel Add-in - Seamless Integration Within Excel
json·excel
wtsolutions4 小时前
Getting Started with JSON to Excel Web App - Convert in Seconds
json·excel·web app
wtsolutions7 小时前
Using the JSON to Excel API - Programmatic Access for Developers
json·excel
qq_435139577 小时前
EasyExcel(FastExcel)Excel导出功能 技术文档
excel
wtsolutions10 小时前
Understanding JSON Formats - What JSON to Excel Supports
json·excel
wtsolutions11 小时前
Advanced Features - Unlocking the Power of JSON to Excel Pro
linux·json·excel
fs哆哆12 小时前
VB.NET和VBA教程-如何查找Excel数据区域边界
excel
小矮强12 小时前
Excel中根据年月日提取月日,并按月日进行排序
excel
开开心心_Every13 小时前
图片批量压缩工具:支持有损无损两种模式
python·游戏·微信·django·pdf·excel·语音识别
wtsolutions14 小时前
Real-World Use Cases - How Organizations Use JSON to Excel
json·excel