0
点赞
收藏
分享

微信扫一扫

使用Pandas的read_html方法读取网页Table表格数据

boomwu 2022-02-28 阅读 25


本文通过一个小实例,说明使用Pandas的read_html方法读取网页Table表格数据

要读取的网页表格数据

http://vip.stock.finance.sina.com.cn/q/go.php/vComStockHold/kind/jjzc/index.phtml

使用Pandas的read_html方法读取网页Table表格数据_html

完整代码

# -*- coding: utf-8 -*-

import pandas as pd

# 数据出现省略号
pd.set_option('display.width', None)

url = 'http://vip.stock.finance.sina.com.cn/q/go.php/vComStockHold/kind/jjzc/index.phtml'

# 可能有多个表格,我们取第一个
df = pd.read_html(url)[0]
# print(data)

# 保存数据
df.to_csv('./data.csv', encoding='utf-8')

打开读取的数据结果,效果还是非常不错的

使用Pandas的read_html方法读取网页Table表格数据_php_02

更多的用法可以研究下文档


参考:
天秀!Pandas还能用来写爬虫?




举报

相关推荐

0 条评论