python - pandas.read_html 返回错误的表格内容
问题描述
我尝试从以下位置刮取两张表(资产和负债):
https://www.marketwatch.com/investing/stock/aapl/financials/balance-sheet
以下是我的代码:
tables = pd.read_html("https://www.marketwatch.com/investing/stock/spg/financials/balance-sheet")
如您所见,刮掉的桌子是完全错误的。
我怎样才能正确刮桌子?
预先感谢您的任何帮助:-)
解决方案
让我们看看这个的 selenium,你也许可以用 bs4 和一些有趣的请求东西来做到这一点
from selenium import webdriver
import time
url = "https://www.marketwatch.com/investing/stock/spg/financials/balance-sheet"
driver = webdriver.Firefox()
driver.get(url)
time.sleep(10)
tables = driver.find_elements_by_class_name("table")
tables[3].text.splitlines() # this looks to split the new line characters
tables[4].text.splitlines()
之后,我认为您可以分配键值对并以这种方式制作数据框,或者使用 numpy
推荐阅读
- react-native - React-navigation 不会在更改时以编程方式更改标题颜色
- r - 如何改变 R 列表对象中的值?
- nexus - Nexus OSS - 无法浏览存储库
- firebase - 约会应用中的 Firebase 数据库建模
- python - Python Opencv:在中断的图片中查找框
- java - 如果未选择命令窗口,批处理文件将暂停
- apache-spark - 复制当前行,修改它并在火花中添加一个新行
- html - 如何仅将 HTML 表格中的某些元素居中?
- javascript - 使用键盘上的 Esc 键关闭模式弹出窗口
- javascript - 循环更改视频分辨率