pythoninstagram-apiimagedownloadinstaloader

Downloading A Picture of an individual Instagram post with with Instaloader and Python


Using Python and the Instaloader package I am able to to download A profile Picture via this code

import instaloader
        dp = instaloader.Instaloader()
        dp.download_profile(profile_name, profile_pic_only = True)

All I have to do is provide the profile name.

What I also want to archive is, I want to download the picture of an individual post, such as: https://www.instagram.com/p/CgbAU5GD6MU/

Can this be done with Python instaloader?

Thanks!


Solution

  • Sure! Get the urls you want and easily use them

    import instaloader
    
    L = instaloader.Instaloader()
    post_url = 'https://www.instagram.com/p/CgbAU5GD6MU/'
    post = instaloader.Post.from_shortcode(L.context, post_url.split('p/')[1].strip('/ '))
    photo_url = post.url   # this will be post's thumbnail (or first slide)
    video_url = post.video_url  # if post.is_video is True then it will be url of video file