Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
431 views
in Technique[技术] by (71.8m points)

Selenium, scroll on a onload scrollbox but the scrolling doesn't stop. "python"

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...