In some cases, we all would have wanted to download the profile picture of a person from Instagram. On Instagram we can only be able to see the profile picture of a user as a very small thumbnail. What if we could view the profile picture of the user and even save it? Python let us do that just with the username of the profile and of-course with some lines of code.
Let us get to the coding part.
This will download the profile picture of Selena Gomez in the current directory.
How does it work?
- Get the username as the input from the user.
- Pass the input to the image function.
- Create a session object from the requests library.
- Get the HTML code using the Beautiful soup library.
- Using regular expression get find “profile_pic_url_hd”
- Get the contents of the URL and download it.
Instead of this code, you can also use the “ig-profile” library which will just have this code and you can directly call the image function from the library.
Install the library using the pip.
pip install ig-profile
from ig_profile import ProfileImage as pimage pimage.image(YOUR_USER_NAME)
The above code will simply download the desired profile picture and open it up in a new window.