【问题标题】:Load Instagram images by scrolling down to bottom of page通过向下滚动到页面底部来加载 Instagram 图像
【发布时间】:2016-01-20 03:33:58
【问题描述】:

以这个 instagram 链接为例。 https://www.instagram.com/janelaverdegarden/,我想通过滚动到页面底部来加载所有图像。为此,我必须单击“加载更多”按钮,向下滚动到底部页面,等待页面加载,向上滚动,然后向下滚动到底部页面并等待页面再次加载,直到没有剩余图像(手动) .

但是,我想使用 Selenium 自动加载页面。因此,最初,我认为一旦页面完全加载到包含所有图像的页面末尾,web 元素rbSensor 将消失,让我可以标记页面已到达底部,不再有图像加载。但是,它仍然存在。那么有没有其他方法可以检查页面是否完全加载了所有图像?

<div data-reactid=".0.1.0.1:$mostRecentSection/=10">
     <div class="_nljxa" data-reactid=".0.1.0.1:$mostRecentSection/=10.0">
     <div class="ResponsiveBlock" data-reactid=".0.1.0.1:$mostRecentSection/=10.1">
             <div class="rbSensor" data-reactid=".0.1.0.1:$mostRecentSection/=10.1.$sensor">
                    <iframe class="rbSensorFrame" data-reactid=".0.1.0.1:$mostRecentSection/=10.1.$sensor.0"/>
                    </div>
      </div>
</div>

代码。由于我使用rbSensor 加载页面,即使页面完全加载了所有图像,该元素仍会被连续单击,因为该元素仍在 html 中。

while (driver.findElements(By.className("rbSensor")).size() > 0) { 
    jse.executeScript("window.scrollTo(0,-300)"); //scroll up abit
    //click on button if found
    driver.findElement(By.className("rbSensor")).click(); 
    Thread.sleep(2000); //pause for 2 seconds
}

Page scroll up or down in Selenium WebDriver (Selenium 2) using java 中使用下面的答案不是我想要的,在这种情况下也不起作用。

jse.executeScript("window.scrollBy(0,250)", "");

【问题讨论】:

    标签: java html selenium scroll


    【解决方案1】:

    尝试使用不同的类名

    className("_oidfu")
    

    有 href 属性

    滚动答案可以在这里找到:Page scroll up or down in Selenium WebDriver (Selenium 2) using java

    【讨论】:

    • _pupj3 仅用于 LOAD MORE,所以即使我点击了它,我仍然需要滚动页面才能加载其余图像
    • @newbie_224466 这个项目的目的是什么?您可以通过获取位于
      中的 img src 属性单击加载更多后获取图像
    • 我想加载 instagram 页面中的所有图片。与单击 LOAD MORE 后一样,如果还有更多要加载的图像,则需要滚动才能加载剩余的图像。我需要一些东西来帮助我确定页面已完全加载,并且没有更多要加载的图像。
    • @newbie_224466 你可以在这里找到答案然后stackoverflow.com/questions/12293158/…
    猜你喜欢
    相关资源
    最近更新 更多
    热门标签