Python 循环仅适用于屏幕中的元素,而不适用于滚动后的元素

Python 循环仅适用于屏幕中的元素,而不适用于滚动后的元素,python,selenium-webdriver,selenium-chromedriver,browser-automation,Python,Selenium Webdriver,Selenium Chromedriver,Browser Automation,我写了一个循环来获取Poshmark壁橱中所有产品的链接。现在Poshmark的工作原理是它显示了48个产品,之后,我们需要滚动加载下一个产品。请检查以下代码。它只适用于48种产品,滚动后,它不适用于这些产品。程序结束时没有任何错误 def loop(): n = 0 container = driver.find_elements_by_css_selector('.tile.col-x12.col-l6.col-s8.p--2') links = [] whi

我写了一个循环来获取Poshmark壁橱中所有产品的链接。现在Poshmark的工作原理是它显示了48个产品,之后,我们需要滚动加载下一个产品。请检查以下代码。它只适用于48种产品,滚动后,它不适用于这些产品。程序结束时没有任何错误

def loop():
    n = 0
    container = driver.find_elements_by_css_selector('.tile.col-x12.col-l6.col-s8.p--2')
    links = []
    while n < 20:  
# I used while loop to go to the end of the page because there is some wait time in scrolling.
        driver.find_element_by_tag_name('html').send_keys(Keys.END)
        n += 1
        time.sleep(5)
    driver.find_element_by_tag_name('html').send_keys(Keys.HOME)
    for item in container:
        listing = item.find_element_by_tag_name('img')
        link = listing.get_attribute('data-src')
        if link not in links:
            links.append(link)
        else:
            pass

    print(len(links))


loop()
def循环():
n=0
container=driver.find_elements_by_css_选择器('.tile.col-x12.col-l6.col-s8.p--2'))
链接=[]
当n<20时:
#我使用while循环转到页面的末尾,因为在滚动中有一些等待时间。
驱动程序。通过标记名(“html”)查找元素。发送密钥(keys.END)
n+=1
时间。睡眠(5)
驱动程序。通过标记名(“html”)查找元素。发送密钥(keys.HOME)
对于容器中的项目:
listing=item.find\u element\u by\u tag\u name('img'))
link=listing.get_属性('data-src')
如果链接不在链接中:
links.append(link)
其他:
通过
打印(len(链接))
循环()