我怎样才能滚动到一些元素并收集数据

how can i scroll until a number of elements and gather data

我想滚动到一定数量的相同元素并收集它们的数据

我使用循环绑定但是我得到这个异常 StaleElementReferenceException: stale element reference: element is not attached to the page document

driver.get("https://unsplash.com/search/photos/beach")
img = []
scroll = driver.find_elements_by_class_name('_2Mc8_')
for num in scroll[0:200]:
    ActionChains(driver).move_to_element(num).perform()
#    ai = driver.execute_script("arguments[0].scrollIntoView();",num)
    print (scroll)
    href = num.get_attribute("href")
    img.append(href)
print (len(img))

这是简单的方法。

url = 'https://unsplash.com/search/photos/beach'
driver.get(url)
while len(driver.find_elements_by_css_selector("figure[itemprop='image']"))<2000:
    driver.find_element_by_xpath("(//figure[@itemprop='image'])[last()]").location_once_scrolled_into_view
print(len(driver.find_elements_by_xpath("//figure[@itemprop='image']")))