1

I need to gather all the "alt" and urls from the images on this website: https://ibb.co/album/D5f4bg

I know how to get that info, just set the driver on the div which contains the image and get all the attributes I need, what stops me is that the images load by scrolling down and not by page number, how could I get all the images to load before gathering the info I need?

user3577419
  • 77
  • 1
  • 7
  • 1
    https://stackoverflow.com/questions/20986631/how-can-i-scroll-a-web-page-using-selenium-webdriver-in-python this might be helpful to understand how to scroll to the bottom of the page and know when to stop, so you can gather all the elements in one go – Shar Jul 20 '21 at 21:32

1 Answers1

1

Just tested this JavaScript code, this will do the trick if you execute it from Selenium:

function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}

let img_count = parseInt(document.querySelector("#album > div.content-width > div.header.header-content.margin-bottom-10 > div.header-content-left > div > div.breadcrum-item.pop-btn.pop-btn-auto.pop-keep-click.pop-btn-desktop > div > div > div > div.user-card-footer > a:nth-child(1) > b").innerText)

let current_img_count = document.getElementsByTagName('img').length;

while(current_img_count < img_count)
{
    window.scrollTo(0,document.body.scrollHeight);
    await sleep(1000);
    current_img_count = document.getElementsByTagName('img').length;
}

Basically, it gets the number of images that is displayed from the websites' visible label, then it compares it to the number of images that are currently present. If the current_image_count is still less than the sites' list amount then it will scroll to the bottom of the page, wait a second, then compare again.

Jason Riek
  • 151
  • 6