Scroll down list instagram selenium and python Scroll down list instagram selenium and python selenium selenium

Scroll down list instagram selenium and python


followers_panel = browser.find_element_by_xpath(XPATH)i = 1while i < number_of_followers:    try:        follower = browser.find_element_by...        i += 1    except NoSuchElementException:        self.browser.execute_script(            "arguments[0].scrollTop = arguments[0].scrollHeight",followers_panel        )

This way you can crawl all of the followers.


I managed to scroll using ActionChain to scroll. But as the list grows and the speed of you computer+Internet, it becomes slow. At first there are only 20-24 names the n 10 names per scroll you can get. Then I used to click the last element as you click the last element, 10 new users appears the you click the last element again. So it goes like this.

from selenium.webdriver.common.action_chains import ActionChainsdef get_list():    element=[]    ran_num=int(random.randint(0,len(subject)-1))    search(subject[ran_num])    br.find_element_by_class_name("_e3il2").click() #open first image    time.sleep(2)    br.find_element_by_partial_link_text('likes').click()    time.sleep(2)    while len(element)<150:            element=br.find_elements_by_xpath("//*[@class='_9mmn5']")            i=len(element)-1            element[i].click()            time.sleep(1.50)    likers=br.find_elements_by_xpath("//*[@class='_2g7d5 notranslate _o5iw8']") #get the username    for i in range(len(likers)):            insta_id=likers[i].text            if (insta_id not in main_list):                main_list.append(insta_id)                with open ('to_like.txt','a') as f:                    f.write('%s\n'%insta_id)    return()


Here is what works. Don't change the sleep times for they allow the scroller to reload new followers without having to scroll it back to the top again.

    FList = driver.find_element_by_css_selector('div[role=\'dialog\'] ul')    numberOfFollowersInList = len(FList.find_elements_by_css_selector('li'))    FList.click()    actionChain = webdriver.ActionChains(driver)    time.sleep(random.randint(2,4))    while (numberOfFollowersInList < max):        actionChain.key_down(Keys.SPACE).key_up(Keys.SPACE).perform()                numberOfFollowersInList = len(FList.find_elements_by_css_selector('li'))        time.sleep(0.4)        print(numberOfFollowersInList)        actionChain.key_down(Keys.SPACE).key_up(Keys.SPACE).perform()                    time.sleep(1)