How can access all of the images in Instagram slides (posts with multiple images or videos) with Instaloader?

965 Views Asked by At

I'm using Instaloader to develop an Instagram scraper bot. here's part of my code that is getting images url from install by each profile:

def scrapImageAddresses(PROFILE):
    print(PROFILE)
    L = Instaloader()
    L.login('####', "####")
    profile = Profile.from_username(L.context, PROFILE)
    imageList = []
    for post in profile.get_posts():
        imageList.append({
            'url': post.url,
            'media_id': post.mediaid
        })
    return imageList

But for slides like this, it only gets the first image of the post. I want all images in the post. How can I do that?

1

There are 1 best solutions below

0
On BEST ANSWER

You can iterate over all sidecar nodes (slides) in every post and add the corresponding url to the list:

def scrapImageAddresses(PROFILE):
    print(PROFILE)
    L = Instaloader()
    L.login('####', "####")
    profile = Profile.from_username(L.context, PROFILE)
    imageList = []
    for post in profile.get_posts():
        for slide in post.get_sidecar_nodes():
            imageList.append({
                'url': slide.video_url if slide.is_video else slide.display_url,
                'media_id': post.mediaid
            })
    return imageList

Documentation: Instagram Structures — Instaloader documentation