【问题标题】:how to get text from twitch redeem points using selenium (python)?如何使用硒(python)从抽搐兑换积分中获取文本?
【发布时间】:2020-05-03 13:56:10
【问题描述】:

我正在尝试从“已兑换突出显示我的消息”抽搐聊天中获取文本,这是我的代码。

from selenium import webdriver

driver = webdriver.Chrome('D:\Project\Project\Rebot Router\chromedriver11.exe')
driver.get("https://www.twitch.tv/nightblue3")

while True:
    text11= driver.find_elements_by_xpath('//*[@id="6583f0b7722e3be4537e78903686d3b4"]/div/div[1]/div/div/section/div/div[3]/div[2]/div[3]/div/div/div[116]/div[2]/span[4]/span')
    text44= driver.find_elements_by_class_name("chat-line--inline chat-line__message")
    print(str(text11))
    print(str(text44))

但是当我运行它时,这就是我得到的

[]
[]
[]
[]
[]
[]
[]
[]
[]

当我像这样使用 .text 时

while True:
    text11= driver.find_elements_by_xpath('//*[@id="6583f0b7722e3be4537e78903686d3b4"]/div/div[1]/div/div/section/div/div[3]/div[2]/div[3]/div/div/div[116]/div[2]/span[4]/span').text
    text44= driver.find_elements_by_class_name("chat-line--inline chat-line__message").text

    print(str(text11))
    print(str(text44))

这就是我得到的

Traceback (most recent call last):
  File "D:/Project/Project/Rebot Router/test.py", line 7, in <module>
    text11= driver.find_elements_by_xpath('//*[@id="6583f0b7722e3be4537e78903686d3b4"]/div/div[1]/div/div/section/div/div[3]/div[2]/div[3]/div/div/div[116]/div[2]/span[4]/span').text
AttributeError: 'list' object has no attribute 'text'

所以请帮忙。 顺便说一句,text11 和 text44 与我在 text11 xpath 和 text44 class_name 中使用的相同。

【问题讨论】:

    标签: python html selenium selenium-webdriver selenium-chromedriver


    【解决方案1】:
    while True:
        Texts = driver.find_elements_by_xpath("//span[@class='text-fragment']")
        for x in range (0, len(Texts)):
            print(Texts[x].text)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-25
      • 1970-01-01
      • 1970-01-01
      • 2015-10-16
      • 2016-12-18
      • 1970-01-01
      • 2021-04-25
      • 1970-01-01
      相关资源
      最近更新 更多