Loop only works for elements in a screen not after scrolling

我的未来我决定 提交于 2021-01-29 07:18:22

问题


I have written a loop to get the links to all the products in Poshmark Closet. Now how Poshmark works is it shows 48 products and after that, we need to scroll to load the next products. Please check the following code. It only works for 48 products and after scrolling, it does not work on those products. The program ends without any error!

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()

来源:https://stackoverflow.com/questions/64274761/loop-only-works-for-elements-in-a-screen-not-after-scrolling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!