栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用BeautifulSoup搜索Yahoo Finance

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用BeautifulSoup搜索Yahoo Finance

好吧,

find_all
返回的列表为空的原因是因为该数据是通过单独的调用生成的,仅通过
GET
向该URL发送请求就无法完成。如果浏览Chrome /
Firefox上的“网络”标签并按XHR进行过滤,则通过检查每个网络操作的请求和响应,您还可以找到应该发送
GET
请求的URL 。

在这种情况下,它是

https://query2.finance.yahoo.com/v10/finance/quoteSummary/AAPL?formatted=true&crumb=8ldhetOu7RJ&lang=en-US&region=US&modules=defaultKeyStatistics%2CfinancialData%2CcalendarEvents&corsDomain=finance.yahoo.com
,我们可以在这里看到:

那么,我们如何重新创建它呢?简单!:

from bs4 import BeautifulSoupimport requestsr = requests.get('https://query2.finance.yahoo.com/v10/finance/quoteSummary/AAPL?formatted=true&crumb=8ldhetOu7RJ&lang=en-US&region=US&modules=defaultKeyStatistics%2CfinancialData%2CcalendarEvents&corsDomain=finance.yahoo.com')data = r.json()

这将以形式返回

JSON
响应
dict
。在此处浏览,
dict
直到找到需要的数据:

financial_data = data['quoteSummary']['result'][0]['defaultKeyStatistics']enterprise_value_dict = financial_data['enterprisevalue']print(enterprise_value_dict)>>> {'fmt': '598.56B', 'raw': 598563094528, 'longFmt': '598,563,094,528'}print(enterprise_value_dict['fmt'])>>> '598.56B'


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/374680.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号