我试图刮这个网页10 Fast Fingers,并希望拉你应该键入到一个列表中的话,这样我就可以键入到下面的文本框。
代码运行了,但是在可见地加载了单词之后,它只加载了空字符串,而不是我所期望的近300个单词。
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
import time
driver = webdriver.Chrome()
driver.get("https://10fastfingers.com/typing-test/english")
driver.find_element(By.ID, "CybotCookiebotDialogBodyButtonDecline").click()
word_list = []
words = driver.find_elements(By.CSS_SELECTOR, "#row1>span[wordnr]")
for word in words:
word_list.append(word.text)
print(word_list)
这是我目前所拥有的,我习惯了python,但不习惯HTML/CSS,所以我在寻找正确的元素时遇到了一些麻烦。
每次的输出都是这样的(每次加载时可见的字都不同)
['mother', 'white', 'might', 'sound', 'us', "it's", 'man', 'home', 'under', 'on', 'tell', 'kind', 'seem', 'the', 'can', 'after', 'just', 'stop', 'on', 'Indian', 'some', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '']
1条答案
按热度按时间olhwl3o21#
好吧,我已经解决了这个问题,以防其他人也遇到同样的问题。每个元素上的.text调用只获取可见文本,所以我使用了.get_attribut(“textContent”),这起作用了。