I am writing a program to get all followers of instagram account, but in order to do that i need to scroll all the way to the end of the followers scroll box to load all elements the thing is I can scroll all the way to the end but the exit condition doesn't work and stop the scroll function from processing.
def get_followers():
# click on the followers link
driver.find_element_by_xpath('//*[@id="react-
root"]/section/main/div/header/section/ul/li[2]/a').click()
time.sleep(1)
# the followers box
scroll_box = driver.find_element_by_xpath('/html/body/div[5]/div/div/div[2]/ul/div')
action = ActionChains(driver)
action.move_to_element(scroll_box).click().perform()
# scrolling to the end to load all element
while last_ht != ht:
# implement the value of the old height with the new height.
last_ht = ht
# the scroll method
driver.execute_script("arguments[0].scrollBy(0,500)", scrollbar)
# a delaty to make sure things did load
time.sleep(2)
# get the new height of the scroll box
ht = driver.execute_script("""arguments.scrollTo(0, arguments[0].scrollHeight);
return arguments[0].scrollHeight;""", scrollbar)
My question is how to get this loop to work probably.
Any help is appreciated, thanks in advance.
question from:
https://stackoverflow.com/questions/65885594/selenium-scroll-on-a-onload-scrollbox-but-the-scrolling-doesnt-stop-python 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…