In this article, we will learn how we can download Instagram posts of a profile using Python Selenium module.
- Google Chrome or Firefox
- Chrome driver(For Google Chrome) or Gecko driver(For Mozilla Firefox)
- Selenium package: It is a powerful tool for controlling a web browser through the program. It is functional for all browsers, works on all major OS and its scripts are written in various languages i.e Python, Java, C#, etc. In can installed using the below command:
pip install selenium
- Beautiful Soap package: It is a Python library for pulling data out of HTML and XML files. It works with your favorite parser to provide idiomatic ways of navigating, searching, and modifying the parse tree.It can installed using the below command:
pip install bs4
- Requests package: Requests library is one of an integral part of Python for making HTTP requests to a specified URL. It can be installed using the below command:
pip install requests
Step 1: Importing modules and entering the login information along with the URL of the page.
Step 2: Function to start the new session of Browser. You might need to add the path to the web driver. Chrome() function, it depends on your installation.
Step 3: Function to enter the URL of the page.
Step 4: Function to enter your login information.
Step 5: Function to open the first post.
Step 6: Function to download all posts.
Step 7: Function to click on next post.
Step 8: Function to save normal Posts.
Step 9: Function to save nested Posts.
Step 10: Function to check if post is nested or not.
Step 11: Calling the required functions in the driver code.
Below is the complete program based on the above approach:
After running this complete script, a directory will be created which will contain all the posts.
Note: If you are Windows user then the posts will be saved with .file extension, open the posts with application which can open both images and videos(Instagram posts have only type of media, image or video)
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course