如何使用BeautifulSoup获取选项数据?

2024-10-03 11:21:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用BS4从雅虎财经的期权合约页面中获取数据。下面是我的测试链接和我为获取所需信息而编写的代码

def get_option_volume(url):
   response = requests.get(url)
   soup = BeautifulSoup(response.text, "html.parser")
   value = soup.findAll(attrs={"data-reactid":"84"})
   for i in value:
       print(i)

get_option_volume("https://finance.yahoo.com/quote/AAPL200221C00320000?p=AAPL200221C00320000")

当我查看页面的HTML数据时,我看到我想要的数据有一个属性为datareact id=84的标记

enter image description here

但是当我运行代码时,我得到的值是一个空变量。我哪里做错了?我查看了文档和其他stackoverflow帖子,但无法找出我的程序失败的地方。它适用于其他随机网站,但不适用于此网站


Tags: 数据代码urlgetvalue网站response页面