批量提取网页表格内容至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')

实现效果

相关推荐
Evan芙12 小时前
用fping编写脚本扫描10.0.0.0/24网段在线主机
linux·运维·网络·excel
SamDeepThinking17 小时前
基于CompletableFuture的主子任务并行处理架构实战:多渠道账单并发导入性能提升5倍的技术方案
java·后端·excel
SamDeepThinking17 小时前
88MB Excel文件导致系统崩溃?看我如何将内存占用降低
java·excel
ChrisitineTX18 小时前
警惕数据“陷阱”:Python 如何自动发现并清洗 Excel 中的异常值?
开发语言·python·excel
wtsolutions18 小时前
Excel to JSON by WTSolutions 4.0.0 版本更新公告
json·excel·wps·插件·转换·加载项·wtsolutions
wtsolutions18 小时前
Excel to JSON by WTSolutions 4.0.0 Update Announcement
json·excel·wps·addin·wtsolutions·conversion
癫狂的兔子2 天前
【Office】【Excel】常用函数公式总结
excel
毛飞龙2 天前
Excel迷你图:在单元格中嵌入趋势洞察
excel·迷你图·sparklines
Tatalaluola2 天前
Unity使用EPPlus读取写入表格
unity·c#·游戏引擎·excel
缺点内向2 天前
如何在 C# 中将 Excel 工作表拆分为多个窗格
开发语言·c#·.net·excel