【发布时间】:2023-04-01 07:25:01
【问题描述】:
我正在创建一个自动化 10fastfingers 的小型 Python 程序。为了做到这一点,我必须首先提取我必须输入的所有单词。所有这些词都存储在span
标签中,如下所示:
当我运行我的代码时,它只提取前 20-30 个单词,而不是提取所有单词。为什么会这样?这是我的代码:
from selenium import webdriver
import time
url = "https://10fastfingers.com/typing-test/english"
browser = webdriver.Chrome("D:\\Python_Files\\Programs\\chromedriver.exe")
browser.get(url)
time.sleep(10)
count = 1
wordlst = []
while True:
try:
word = browser.find_element_by_xpath(f'//*[@id="row1"]/span[{count}]')
wordlst.append(word.text)
count += 1
except:
break
print(wordlst)
输出:
['them', 'how', 'said', 'light', 'show', 'seem', 'not', 'two', 'under', 'hear', 'them', 'there', 'about', 'face', 'us', 'change', 'year', 'only', 'leave', 'number', 'found', 'father', 'people', 'house', 'really', 'my', 'spell', 'when', 'look', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '']
如何解决这个问题?任何帮助,将不胜感激。谢谢!
【问题讨论】:
标签:
python
selenium
selenium-chromedriver
screen-scraping
本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:Selenium Python 无法在所有跨度标签中提取文本 - Python技术站