我正在尝试从"兑换突出显示我的消息"twitch聊天中获取文本,这是我的代码。
from selenium import webdriver
driver = webdriver.Chrome('D:ProjectProjectRebot Routerchromedriver11.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中使用的相同。
while True:
Texts = driver.find_elements_by_xpath("//span[@class='text-fragment']")
for x in range (0, len(Texts)):
print(Texts[x].text)