如何使用html类名进行刮取?

2024-04-26 19:02:47 发布

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

我试图理解刮取的逻辑以及如何找到搜索到的数据。 我正在尝试浏览以下网站:

website

当我使用下面的代码时:

import requests
from bs4 import BeautifulSoup

page = requests.get('https://fr.finance.yahoo.com/')
soup = BeautifulSoup(page.text,'html.parser')

y = soup.find(id="market-summary")
print(y)

结果就是我想要的

但是,当我尝试使用代码复制结果时:

import requests
from bs4 import BeautifulSoup

page = requests.get('https://fr.finance.yahoo.com/')
soup = BeautifulSoup(page.text,'html.parser')

x = soup.find("div", class_= 'Whs(nw) D(ib) Bgc($lv2BgColor) W(100%) Bxz(bb)')
print(x)

结果我得到了“无”。 有人能解释一下我做错了什么吗?如何使用“class”作为标记来查找我要查找的数据


Tags: 数据代码fromhttpsimportcomgetpage