【问题标题】:Cannot scrape crumb from yahoo finance无法从雅虎财经中刮取面包屑
【发布时间】:2019-02-10 19:58:10
【问题描述】:

我正在尝试从雅虎金融股票中抓取历史数据。我从互联网上找到了一些代码并对其进行了修改。起初它有效,但现在我无法从雅虎刮掉面包屑。谁能建议如何解决这个问题?

第一次刷yahoo,它刷了20组数据,就停止工作了。我又开始了,还是不行

下面附上相关代码

def _get_crumbs_and_cookies(stock):
    """
    get crumb and cookies for historical data csv download from yahoo finance

    parameters: stock - short-handle identifier of the company 

    returns a tuple of header, crumb and cookie
    """

    url = 'https://finance.yahoo.com/quote/{}/history'.format(stock)
    with requests.session():
        header = {'Connection': 'keep-alive',
                   'Expires': '-1',
                   'Upgrade-Insecure-Requests': '1',
                   'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) \
                   AppleWebKit/537.36 (KHTML, like Gecko) 
                   Chrome/54.0.2840.99 Safari/537.36'
                   }

        website = requests.get(url, headers=header)
        soup = BeautifulSoup(website.text, 'lxml')
        crumb = re.findall('"CrumbStore":{"crumb":"(.+?)"}', str(soup))

    return (header, crumb[0], website.cookies)

完整的原始代码可以在以下位置找到: https://maikros.github.io/yahoo-finance-python/

提前感谢您的帮助

【问题讨论】:

  • 欢迎来到 Stack Overflow。听起来雅虎财经可能阻止了你,或者你做了一个改变,破坏了抓取。稍后再试,看看它是否有效(阻塞通常是暂时的)。

标签: python yahoo-finance


【解决方案1】:

我认为你应该在这里看看这篇文章:Yahoo Finance API / URL not working: Python fix for Pandas DataReader

看起来雅虎财经已经停止了他们的历史数据:(

你可以试试谷歌!但是,Google 并不是一个真正可行的选择,因为他们会根据拆分调整价格,而不是根据股息调整价格。

希望这会有所帮助!

【讨论】:

    【解决方案2】:

    一周前我一直在寻找金融 API。 我想,雅虎或谷歌应该提供一个好的,但我不得不发现,两者都已经停产了。

    目前我使用的是WorldTradingData,每天可以免费处理 250 个请求。我不知道您将使用哪种规模,但如果您需要此应用程序,他们还提供付费订阅,可能有更多请求。 我发现他们的客户支持非常友善且乐于助人,因为我发现一些实时报价是错误的,并且仅在一天后他们就已经切换了他们从中获取数据的位置,一切都再次变得很棒!

    我希望这能让你到达你想去的地方!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-01
      • 2021-06-03
      • 1970-01-01
      • 1970-01-01
      • 2012-06-26
      • 1970-01-01
      • 1970-01-01
      • 2020-04-01
      相关资源
      最近更新 更多