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

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

要读取的网页表格数据
http://vip.stock.finance.sina.com.cn/q/go.php/vComStockHold/kind/jjzc/index.phtml

在这里插入图片描述
完整代码

# -*- 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还能用来写爬虫?

发布了1488 篇原创文章 · 获赞 454 · 访问量 158万+

猜你喜欢

转载自blog.csdn.net/mouday/article/details/105278570
今日推荐