首页 > 解决方案 > 程序在工作过程中出错

问题描述

抓取网站时,一切顺利,直到程序在向下滚动几次后出现此错误

selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document
  (Session info: chrome=91.0.4472.77)
def gsrc(A):
    [list_src.add(src.get_attribute("src"))  for src in A]

for i in range(100):
    b.execute_script("window.scrollTo(0,document.body.scrollHeight);")
    A=b.find_elements_by_css_selector('.KL4Bh img')
    gsrc(A)
    time.sleep(5)

是什么原因?

标签: pythonselenium

解决方案


推荐阅读