向下滚动 Followers/Following Instagram 框中的列表

Scroll down Followers/Following List in the Instagram Box

你好 :) 我正在寻找一种解决方案来向下滚动 Instagram Box 中的 following/followers 列表。 我做的步骤如下:

显示关注者列表后,当我使用以下行向下滚动时:

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

我知道框下方的页面向下滚动:(

如何向下滚动关注者框中的列表?

提前致谢:) 玛丽亚

您可以尝试 execute_script() 并更改 .isgrP 如果不同 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
''')

这种方法非常适合我的情况。请不要更改循环内的睡眠时间。它们允许在对话框中重新加载 followers/following 而无需向上滚动。

    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)

您可以通过以下方法进行测试。我测试过并且有效。

    """Scroll a specific element one or more times with small delay between
    them."""

    while times > 0:
        self.driver.execute_script(
            'arguments[0].scrollTop = arguments[0].scrollHeight',
            element
        )
        time.sleep(.2)
        times -= 1