【问题标题】:Scrolling through instagram's follower list with python/selenium使用 python/selenium 滚动浏览 Instagram 关注者列表
【发布时间】:2019-11-24 01:11:07
【问题描述】:

当我在 Instagram 上单击我的关注者页面时,会出现一个对话框,我需要它向下滚动并浏览列表。我当前的代码有效,但问题是它滚动得太快,因此 instagram 将其锁定,无法查看更多个人资料。我可以使用什么命令来降低滚动速度以更接近地模仿人类?

WebDriverWait(driver, 10).until(lambda d: d.find_element_by_css_selector('div[role="dialog"]'))

driver.execute_script('''
    var fDialog = document.querySelector('div[role="dialog"] .isgrP');
    fDialog.scrollTop = fDialog.scrollHeight
''')

【问题讨论】:

    标签: javascript python


    【解决方案1】:

    您可以编写一个滚动一定数量像素的函数,然后暂停一定数量的毫秒,直到达到目标滚动长度。

    function scrollByPixels(px, pause, target) {
      document.documentElement.scrollTop += px
      if (target > px) {
        setTimeout(scrollByPixels, pause, px, pause, target - px)
      }
    }
    
    scrollByPixels(10, 100, 1000)
    body {
      height: 1000px;
      background-image: linear-gradient(to bottom, dodgerblue, indigo);
    }

    用法:

    scrollByPixels(10, 100, 1000)
    

    参考资料:

    setTimeout

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多