简体   繁体   English

向下滚动到页面底部以加载Instagram图片

[英]Load Instagram images by scrolling down to bottom of page

Taking this instagram link for eg. 以这个Instagram链接为例。 https://www.instagram.com/janelaverdegarden/ , I want to load all the images by scrolling to the bottom of the page. https://www.instagram.com/janelaverdegarden/ ,我想通过滚动到页面底部来加载所有图像。 To do that, I have to click LOAD MORE button, scroll down to bottom page, wait for page to load, scroll up abit, and scroll down to bottom page and wait for page to load again till no more images are left (manually). 为此,我必须单击“加载更多”按钮,向下滚动至底部页面,等待页面加载,向上滚动,然后向下滚动至底部页面,等待页面再次加载,直到没有剩余图像为止(手动) 。

However, I want to load the page automatically using Selenium. 但是,我想使用Selenium自动加载页面。 Thus, initially, I thought that once the page is fully loaded to the end of the page with all the images, the web element rbSensor will disappear, allowing me to mark that the page has reached the bottom with no more images to be loaded. 因此,最初,我认为一旦页面全部包含所有图像都加载到页面的末尾,Web元素rbSensor就会消失,这使我能够标记该页面到达底部而没有更多图像要加载。 However, it still remains there. 但是,它仍然保留在那里。 So is there any other way to check if the page is fully loaded with all the images? 那么,还有其他方法可以检查页面是否完全加载了所有图像吗?

<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>

Code . 代码 As I used rbSensor to load the page, even if the page is fully loaded with all the images, the element will still be clicked continuously as the element is still in the html. 当我使用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
}

Using the answer below in Page scroll up or down in Selenium WebDriver (Selenium 2) using java is not what I want and will not work in this case. 使用java在Selenium WebDriver(Selenium 2)中向上或向下滚动页面中使用下面的答案不是我想要的,在这种情况下将不起作用。

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

Try using a different class name 尝试使用其他类名

className("_oidfu")

has href attribute 具有href属性

Scrolling answer can be found here: Page scroll up or down in Selenium WebDriver (Selenium 2) using java 可以在这里找到滚动答案: 使用Java在Selenium WebDriver(Selenium 2)中向上或向下滚动页面

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM