• Home
  • Windows
    • Windows 10
    • Windows 11
  • Mac
  • iOS
  • iPad
  • iPhone
  • Social Media
  • News
Wednesday, March 22, 2023
HowToFixIssue
Advertisement
  • Home
  • Windows
    • Windows 10
    • Windows 11
  • Mac
  • iOS
  • iPad
  • iPhone
  • Social Media
  • News
No Result
View All Result
  • Home
  • Windows
    • Windows 10
    • Windows 11
  • Mac
  • iOS
  • iPad
  • iPhone
  • Social Media
  • News
No Result
View All Result
HowToFixIssue
No Result
View All Result
Home Social Media Instagram

How to Download an Instagram Profile Pic Using Python

October 14, 2022
in Instagram
Reading Time: 12 mins read
How to Download an Instagram Profile Pic Using Python

InterestingPosts

How to Make a Custom Alarm on iPhone [2023]

How to Right-Click Without a Mouse/Trackpad on Mac

How to Obtain an Instagram Profile Pic Utilizing Python.

The profile image is likely one of the prime components of any social media account however functions corresponding to Instagram do not let you view or obtain it. This course of may be simply achieved utilizing an online automation instrument corresponding to Selenium with Python.


Be taught to make use of this energy duo to work together with any factor of a webpage, automate it, and save your self invaluable time investing in productive duties. And the very best part? Construct this with out even logging in or having an Instagram account.!


The Algorithm Constructing Course of

Algorithm constructing refers back to the strategy of figuring out the issue and itemizing the steps this system must automate. The totally different steps required to obtain a profile image are:

  1. Take the username of a profile as enter
  2. Open Google Chrome
  3. Go to the Instagram profile
  4. Obtain the profile image

This serves because the algorithm of the issue assertion.

This undertaking makes use of the next Python modules and instruments.

1. Urllib Module

Urllib is a Python module used to deal with URLs from the web. You will use this module to obtain the profile image of the account from its supply URL. If Urllib isn’t current in your system, you’ll be able to set up it utilizing the command pip set up urllib.

2. Time Module

This module, whereas not necessary, might trigger the construct to fail in case your web connection is sluggish or the contents of the webpage aren’t loaded in the course of the time of Python program interplay with the webpage. The delay() perform helps us put a small delay in order that the construct does not fail.

3. Selenium Module

Probably the most well-liked open-source browser automation instruments is Selenium. It’s accessible as a Python bundle supporting numerous browsers corresponding to Google Chrome, Microsoft Edge, Safari, and Mozilla Firefox. To put in Selenium in your Python atmosphere, open your Terminal and execute pip set up selenium.

4. WebDriver

An internet driver is a instrument utilized by Selenium that establishes a connection between this system and any web site. Totally different sorts of internet drivers can be found based mostly on the browser you wish to automate. For this construct, you’re going to use Google Chrome browser. To put in the online driver for Chrome:

  1. Verify the model of the browser you are utilizing by visiting the Menu (3 dots) >Assist > About Google Chrome.
    About Google Chrome Page
  2. Word the model of the browser.
    Chrome Browser Version
  3. Go to the downloads web page of ChromeDriver – WebDriver for Chrome.
  4. Choose the choice that matches your model quantity from the present releases of ChromeDriver.
    Web Driver Chrome
  5. Select and obtain the file in keeping with your working system.
    Web Driver Chrome Windows Download
  6. Extract the downloaded file and place it in the identical folder as your Python program. This can be useful in setting the trail throughout coding.

How to Examine Code for Automating Any Facet of a Internet Web page

For any internet automation course of utilizing Selenium and Python, it’s important to have a primary understanding of the online and its applied sciences. Step one is to realize an introduction to HTML adopted by understanding Cascading Model Sheets (CSS). That is the place you will get accustomed to the idea of ids and courses.

Ids and courses are distinctive names given to a component or set of components (tags) respectively. Utilizing these you find the required factor and instruct the Python program to focus on it particularly. To examine the code and find the profile image:

  1. Open the webpage of the Instagram account.
  2. Click on on the browser Menu > More Instruments > Developer Instruments or use the shortcut Ctrl + Shift + I to activate the Developer Instruments view.
    Developer Tools Chrome
  3. Click on and choose the Component Picker instrument (mouse cursor icon) within the left nook of the window and hover it over any a part of the webpage to leap to that part of code.
    Element Picker Developer Tools
  4. It is very important observe that the profile photos of a public account and a non-public account are set otherwise. Hover the cursor over the profile pic of a public account. The category attribute for the Public Profile is _aa8j.
    Public Profile Image Class
  5. Repeat the above step for a non-public profile. The category attribute is _aadp.
    Private Profile Image Class

You should use this process to grasp any internet web page and goal any factor for automation.

How to Construct the Instagram Profile Pic Downloader

Observe these steps to create the downloader.

  1. Import the required modules into the Python atmosphere.
    from selenium import webdriver
    import time
    import urllib.request
  2. Utilizing the enter perform, achieve the username of the profile whose profile image is to be downloaded and retailer it in a variable known as username.

    username=enter("Enter the username of the profile: ")
  3. Initialize the online driver by creating an object of it and passing its file system path.

    cd='chromedriver.exe'
  4. Use the webdriver.Chrome perform to launch the Google Chrome browser.

    driver = webdriver.Chrome(cd)
  5. The URL of any Instagram account is of the format https://www.instagram.com/ adopted by the username. Set the URL of the profile as,

    url='https://www.instagram.com/'
    url_p=url+user_h
  6. Go the entire URL of the Instagram profile to be visited to the get() perform.

    driver.get(url_p)
  7. Set an optionally available beneficial delay for the online web page to load fully.

    time.sleep(5)
  8. Use the try-except block to find and decide if the profile image belongs to a public profile. That is carried out by utilizing the category attribute within the XPath expression. In case of failure, use the besides block to go looking the profile image of a non-public account.
    attempt:
    picture=driver.find_element_by_xpath('//img[@class="_aa8j"]')
    besides:
    picture=driver.find_element_by_xpath('//img[@class="_aadp"]')
  9. Utilizing the get_attribute(), achieve the src attribute of the picture. This returns the hyperlink of the picture.

    img_link=picture.get_attribute('src')
  10. Set the trail and extension of the downloaded file. As an example, you’ll be able to set the image to be downloaded to the D: drive of your file system in JPG format as.

    path="D:"+username+".jpg"
  11. Obtain the picture by passing the hyperlink of the profile image because the supply and the native system folder path because the vacation spot to the urlretrieve() perform.

    urllib.request.urlretrieve(img_link,path)
  12. Go to the folder and see that the profile image has been downloaded. Optionally, you can too show the trail the place the profile image has been downloaded.

    print("The profile pic has been downloaded at: "+path)

Last Supply Code for Instagram Profile Pic Downloader Utilizing Python

Bringing all of it collectively, you get:


from selenium import webdriver
import time
import urllib.request
user_h=enter("Enter the username of the profile: ")
url='https://www.instagram.com/'
url_p=url+user_h
cd='chromedriver.exe'
driver = webdriver.Chrome(cd)
driver.get(url_p)
time.sleep(5)
attempt:
picture=driver.find_element_by_xpath('//img[@class="_aa8j"]')
besides:
picture=driver.find_element_by_xpath('//img[@class="_aadp"]')


img_link=picture.get_attribute('src')

Purposes of Internet Automation

Automation not solely helps you save time, cash, and energy but additionally ensures the completion of duties whereas stopping errors. Use this system to automate the login of various web sites, carry out cloud servers backup, schedule messages, want birthdays on social media platforms, create posts, publish tweets, and plenty of more.



Check out more article on – How-To tutorial and latest highlights on – Instagram Information, Open Instagram


Tags: Fix Instagram ErrorFix Instagram IssueHow to Fix InstagramHow To Fix IssueHow to Social Media IssueHow to Social Network IssueHow-To-3-InstagramInstagraminstagram Fixinstagram Fix Issueinstagram Helpinstagram Issue Solutioninstagram Issuesinstagram Solutionsinstagram Troubleshootingsocial mediaSocial NetworkSocial NetworksSolutions

Recommended.

Windows 11 critical process died? Here’s how to fix it

Windows 11 critical process died? Here’s how to fix it

March 12, 2023
How To Outlook Search By Date To Find Emails Quickly!

How To Outlook Search By Date To Find Emails Quickly!

October 23, 2022

Trending.

No Content Available
  • About
  • Advertise
  • Privacy & Policy
  • Contact
All about technical, android, mobile, windows relating website. We provide you with the latest technology straight from the industry.

© 2023 How To Fix Issue - All rights reserved.

No Result
View All Result
  • Home
  • Windows
    • Windows 10
    • Windows 11
  • Mac
  • iOS
  • iPad
  • iPhone
  • Social Media
  • News

© 2023 How To Fix Issue - All rights reserved.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
SAVE & ACCEPT
This website uses cookies. By continuing to use this website you are giving consent to cookies being used. Visit our Privacy and Cookie Policy.
Go to mobile version