我想用Selenium从这个网站上刮取类“tore dots”的所有文本值:https://www.fussballdaten.de/vereine/fc-bayern-muenchen/2019/
因此,我使用以下函数:
dots_graph = driver.find_element_by_class_name("tore-dots")
dots_graph.text
结果是一个串联字符串,如:“6121198912101179685765554353454333”
但是,数字代表不同的位置,最多两位数。 如何使用分隔符符号刮除文本。例如,所有不同的元素在列表中分开,而不是在字符串中串联
在获得
dots_graph
之后,您应该使用dots_graph.find_elements_...
(单词elements
中的字符s
)来搜索dots_graph
中的所有<text>
作为分隔元素,然后您应该使用for
-loop从每个<text>
中获取.text
或者您可以尝试在一个
xpath
中获取tore-dots
和<text>
或者与
CSS
选择器相同顺便说一句:
.text
并不意味着<text>
就像它在beautifulsoup
中的意思一样编辑:
最小工作代码
您可以使用
driver.execute_script
获取文本值:输出:
相关问题 更多 >
编程相关推荐