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

实现效果

相关推荐
UR的出不克12 小时前
使用 Python 爬取 Bilibili 弹幕数据并导出 Excel
java·python·excel
wtsolutions12 小时前
Understanding Excel Data Formats - What Excel to JSON Supports
ui·json·excel
ぁず12 小时前
excel想生成一列随机数并删除公式保留值
excel
wtsolutions15 小时前
Real-World Use Cases - How Organizations Use Excel to JSON
json·github·excel
一只小H呀の15 小时前
pandas处理excel数据
excel·pandas
wregjru15 小时前
【操作系统】3.开发工具
excel
wtsolutions18 小时前
MCP Service Integration - Excel to JSON for AI and Automation
人工智能·json·excel
wtsolutions1 天前
JSON to Excel Add-in - Seamless Integration Within Excel
json·excel
wtsolutions1 天前
Getting Started with JSON to Excel Web App - Convert in Seconds
json·excel·web app
wtsolutions1 天前
Using the JSON to Excel API - Programmatic Access for Developers
json·excel