【问题标题】:Trying to scrape the Yahoo finance "World Indices" List试图刮掉雅虎财经“世界指数”榜单
【发布时间】:2021-09-22 13:13:45
【问题描述】:

我正在尝试使用以下代码将 Yahoo Finance(https://finance.yahoo.com/world-indices/) 中的“世界指数”列表抓取到数据框中。但是,当我收到以下信息时:

ValueError: 未找到表

import pandas as pd
major_indices = pd.read_html("https://finance.yahoo.com/world-indices/")
df = pd.read_html(driver.find_element_by_id("history_table").get_attribute('outerHTML'))[0]
df.head()

Output:
ValueError: No tables found

我尝试检查页面,发现桌子被包围了


<tbody data-reactid="36"> ... </tbody>. 

我试图搜索如何进行抓取,但没有任何运气。

熊猫数据阅读器是要走的路吗?有没有更强大的网络爬虫我应该使用,例如 selenium 或 beautiful soup?

【问题讨论】:

    标签: python html web-scraping


    【解决方案1】:

    我建议研究 BeautifulSoup 以使用 Python 进行网络抓取。如果您使用像 PyCharm 这样的 IDE,浏览 BeautifulSoup 对象以查找网页内容应该不会太难。

    这是您的示例的入门。

    from bs4 import BeautifulSoup
    import requests
    
    website_html = requests.get("https://finance.yahoo.com/world-indices/").text
    soup = BeautifulSoup(website_html)
    table = soup.find("tbody", {"data-reactid": "36"})
    table_text = [[cell.text for cell in row.contents] for row in table.contents]
    

    【讨论】:

      猜你喜欢
      • 2017-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-03
      • 1970-01-01
      • 2019-02-10
      • 1970-01-01
      相关资源
      最近更新 更多