Python selenium 'list' 对象没有属性 'text' 错误

spa*_*cey 2 python selenium

我正在尝试从网站上的评论中复制文本,<span class="auto-link">yes</span> 而我的 python 代码是

element=browser.find_elements_by_xpath('//span[@class="auto-link"][1]')
print(element.text)
Run Code Online (Sandbox Code Playgroud)

但我不断收到“列表”对象没有属性“文本”错误,我不知道我做错了什么。

小智 6

我在 python 中使用硒。试试这个代码我希望这对你有用。

    element=browser.find_elements_by_xpath('//span[@class="auto-link"][1]')

    for value in element:
        print(value.text)
Run Code Online (Sandbox Code Playgroud)