所以我使用硒抓取链接。我可以用循环打印我的链接,但我无法导航到它们,因为我收到以下错误:
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)