Skip to main content
 首页 » 编程设计

python之find_element_by_class_name 类空间不起作用

2025年05月04日20yxwkf

我正在尝试使用 find_element_by_class_name 类有空格但它不起作用:

代码如下:

<a class="yt-simple-endpoint style-scope yt-formatted-string" href="/user/santanderbrasil">Santander Brasil</a> 

我想要获取内容“Santander Brasil”

我尝试了以下方法:

driver.find_element_by_class_name("yt-simple-endpoint.style-scope.yt-formatted-string")     
driver.find_element_by_class_name("a.yt-simple-endpoint.style-scope.yt-formatted-string") 

和

driver.find_element_by_class_name("a.yt-simple-endpoint.") 

没有一个工作...

有什么帮助吗?

请您参考如下方法:

改为使用 css 选择器函数。

driver.find_element_by_css_selector("a.yt-simple-endpoint.style-scope.yt-formatted-string")