硒无法向下滚动Instagram帖子喜欢列表

时间:2020-05-20 04:15:07

标签: javascript python selenium instagram

我无法向下滚动instagram帖子赞列表中的无限滚动。我有一个可以滚动的滚动条,但它滚动了人的主要instagram个人资料的背景页面,而不是该帖子中的喜欢者列表。我不包含的代码只是使机器人到达了帖子并打开了喜欢的人的列表,这些人在被抓取时仅检索前12个喜欢的人,因为它需要滚动到底部才能加载完整列表。

def _get_likes(self):
    SCROLL_PAUSE_TIME = 1

    # Get scroll height
    last_height = self.driver.execute_script("return document.body.scrollHeight")
    while True:
        # Scroll down to bottom
        self.driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
        # Wait to load page
        sleep(SCROLL_PAUSE_TIME)
        # Calculate new scroll height and compare with last scroll height
        new_height = self.driver.execute_script("return document.body.scrollHeight")
        if new_height == last_height:
            break
        last_height = new_height

0 个答案:

没有答案