小编Big*_*aBX的帖子

陈旧; 元素不再附加到 DOM,不在当前框架上下文中,或者文档已刷新

所以我使用硒抓取链接。我可以用循环打印我的链接,但我无法导航到它们,因为我收到以下错误:

selenium.common.exceptions.StaleElementReferenceException:消息:元素引用已过时;元素不再附加到 DOM,不在当前框架上下文中,或者文档已刷新

from selenium import webdriver

driver = webdriver.Firefox()

driver.get("https://www.famousgraphicdesigners.org/")

links = driver.find_elements_by_xpath('//*[@id="pages-2"]/div/ul/li/a')
links_total = len(links)
print("Found", links_total, "total links.\n")

for i in links:
    # print(i.get_attribute('href')) # This works
    driver.get(i.get_attribute('href')) # This doesnt work

driver.quit()
Run Code Online (Sandbox Code Playgroud)

python selenium selenium-webdriver python-3.8

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

python ×1

python-3.8 ×1

selenium ×1

selenium-webdriver ×1