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