Scroll down Followers/Following List in the Instagram Box

我们两清 提交于 2020-05-28 05:28:23

问题


Hi :) I was looking for a solution to scroll down the following/followers list in the Instagram Box. The step I do are the following:

  • open an IG profile of the user A;
  • click on the button "followers";
  • a box with a list of 12 followers appears in a IG box.

Once the followers list is shown up, when I scroll down using the line:

driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")

I get that the page below the box scrolls down :(

How can scroll down the list in the followers box?

Thanks in advance :) Maria.


回答1:


you can try execute_script() and change .isgrP if different class

...
from selenium.webdriver.support.ui import WebDriverWait 
.....
# after click follower link, wait until dialog appear
WebDriverWait(driver, 10).until(lambda d: d.find_element_by_css_selector('div[role="dialog"]'))
# now scroll
driver.execute_script('''
    var fDialog = document.querySelector('div[role="dialog"] .isgrP');
    fDialog.scrollTop = fDialog.scrollHeight
''')



回答2:


This method works perfectly for my situation. Don't change the sleep times within the loop please. They allow reload of followers/following within the dialogue box without having to scroll back up.

    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)


来源:https://stackoverflow.com/questions/53681446/scroll-down-followers-following-list-in-the-instagram-box

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