问题
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