首页 > 解决方案 > find_element_by_class_name 类空间不起作用

问题描述

我正在尝试使用find_element_by_class_name班级有空格但不起作用的地方:

这是代码:

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

我想要获取内容“桑坦德巴西”

我尝试了以下方法:

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.")

没有一个工作...

有什么帮助吗?

标签: pythonseleniumselenium-webdriver

解决方案


请改用 css 选择器功能。

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

推荐阅读