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

实现效果

相关推荐
shenzhenNBA8 小时前
python用openpyxl操作excel-读取或创建excel文件
python·excel·读取excel·创建excel文件
shenzhenNBA8 小时前
python用openpyxl操作excel-单元格操作
python·excel·单元格操作
商bol458 小时前
答案解析5
excel
ohoy1 天前
EasyPoi 数据脱敏
开发语言·python·excel
开开心心_Every1 天前
Word转PDF工具,免费生成图片型文档
网络·笔记·pdf·word·powerpoint·excel·azure
艾上编程2 天前
第一章——办公自动化之Excel拆分工具:精准处理数据,提升办公效能
自动化·excel
夜流冰2 天前
Excel - MS Support for Excel: Get started
excel
缺点内向2 天前
如何在 C# 中创建、读取和更新 Excel 文档
c#·.net·excel
YuanYWRS2 天前
办公基础:实现PDF中表单不改变格式的情况下转成excel
pdf·excel
Data_agent2 天前
Python高效实现Excel与TXT文本文件数据转换指南
开发语言·python·excel