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?

1
  • 1
    stackoverflow.com/questions/20986631/… 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 Commented Jul 20, 2021 at 21:32

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.