In this article, we will discuss how to download Instagram reel using Python.
Instagram is a social networking platform owned by Facebook. In Python, there are numbers of libraries available by which we can solve some real-life problems and it also provides some tools to scrape information from Instagram. One of the tools is Instascrape Python Package. Instascrape is the powerful Instagram data scrapping toolkit.
Installation :
Install insta-scrape library from PyPI
pip install insta-scrape
To download reels from Instagram first import all the required libraries. In our example, we are importing the time module because while saving the file we will concatenate time with the filename to avoid naming conflict. Now add Session-Id and Headers. Session-Id is valid until you logged out. so when u will next time, again you need to pass a new session-id that time. ( You will get your session-id in Session Storage by Inspecting the page ). It is not that easy to scrape data directly due to updated policies of Instagram so we have to pass the session id into the headers. Using Reel Module and Providing Download Location we can get the job done.
Syntax:
insta_reel=Reel(‘instagram link’)
insta_reel.scrape(headers=headers)
insta_reel.download(download_path.mp4″)
By following the above procedure, you will get downloaded reel in your specified directory.
Example: Download Instagram reels using Python
- Python3
from instascrape import Reel import time # session id SESSIONID = "Paste session Id Here" # Header with session id headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)\ AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.74 \ Safari/537.36 Edg/79.0.309.43", "cookie": f'sessionid={SESSIONID};'} # Passing Instagram reel link as argument in Reel Module insta_reel = Reel('https://www.instagram.com/reel/CKWDdesgv2l/?utm_source=ig_web_copy_link') # Using scrape function and passing the headers insta_reel.scrape(headers=headers) # Giving path where we want to download reel to the # download function insta_reel.download(fp=f".\\Desktop\\reel{int(time.time())}.mp4") # printing success Messageprint('Downloaded Successfully.') |
Output:
That’s it!! Thank You.
I have written the same article on GeeksforGeeks as well.
If you also wish to share your knowledge with the TheCodeSpace fam kindly share your thoughts/article on rajparmar2308@gmail.com.
Hi i want to use this code on Centos server
But it’s not working.
Do u have any working script for Linux server. I tried almost all available things on Linux but not able to found any solution regarding Linux server
Reading your article helped me a lot and I agree with you. But I still have some doubts, can you clarify for me? I’ll keep an eye out for your answers.