首页 > 解决方案 > 使用 Selenium 将 Instagram 个人资料图片滚动到最后

问题描述

我需要使用 Selenium 将 Instagram 个人资料图片滚动到最后。

我正在使用这段代码:

long last_height = (long)js.ExecuteScript("return document.body.scrollHeight");

while (true) {
     js.ExecuteScript("window.scrollTo(0, document.body.scrollHeight);");

     System.Threading.Thread.Sleep(1500);
     long new_height = (long)js.ExecuteScript("return document.body.scrollHeight");

     if (new_height == last_height) {
         break;
     }

     last_height = new_height;
}

但是这个实现有一个问题,如果页面在 1.5 秒内没有更新,它就会停止滚动。

我注意到当页面刷新时,底部会出现一个加载图标。

在此处输入图像描述

是否有可能以某种方式跟踪此图标是否出现?

或者您知道问题的另一种解决方案吗?

编辑:

我注意到,在加载所有图片之前,此图标(更新图像时可见,用户不向下滚动时不可见)存在,并且当所有内容加载时它完全消失。

剩下的只是检查这个元素的存在。

在此处输入图像描述

标签: c#seleniuminstagram

解决方案


推荐阅读