Downloading recent Instagram photos using instascrape and Python
In this post, I’m going to show you how to download a user’s recent Instagram photos programatically using the expressive and lightweight instascrape library in 3 easy steps!
Loading the profile
To start, we will use instascrape.Profile
to load an Instagram profile's necessary data (for this example, we'll use my page @chris_greening.
Getting the recent posts
From this Profile
object, we can now get a list
of instascrape.Post
objects and filter them so that we don't download any videos
Downloading the images
And now the moment we’ve all been waiting for! instascrape.Post
provides the download
method which takes a filepath string as an argument to download our image to.
We’re going to loop through all of the Post
instances in chris_photos
and create a unique filename based on its datetime stored in upload_date
(i.e. "2020-09-09 10h24m.png"
).
The result
It’s as easy as that! Currently, instascrape
only supports downloading images but I hope to expand it in the near future to videos as well 🎥
If you want to learn more, come on over to the official repo and leave it a star! I’m always looking for new contributors 😄.