1. This website uses cookies to improve service and provide a tailored user experience. By using this site, you agree to this use. See our Cookie Policy.
    Dismiss Notice

Help: Scrape Insta Followers using Python

Discussion in 'Instagram' started by Chris B, Sep 21, 2017.

  1. Chris B

    Chris B Newbie

    Joined:
    Jun 29, 2017
    Messages:
    24
    Likes Received:
    1
    Gender:
    Male
    Hello,

    I am trying to do something extremely simple in python yet somehow it's very hard. All I want to do is write a python script that records the number of people a instagram user is following, and the number of it's followers. That's it.

    Can anyone point me to a good package to do this? preferably not beautiful soup as that is overly complicated for what I want to do. Is there an instagram specific python library?

    The account I want to scrape is public. This is very simple to do for twitter.

    Any help is appreciated.

    Thanks
     
  2. JJJackson

    JJJackson Jr. VIP Jr. VIP

    Joined:
    May 21, 2016
    Messages:
    580
    Likes Received:
    391
    Occupation:
    Gatekeeper
    Home Page:
    You would need to download the web page of the users you want to know the stats of and use an http parser.

    Code:
    from lxml import html
    import requests
    
    page = requests.get('https://www.instagram.com/selenagomez/')
    tree = html.fromstring(page.content)
    
    followers = tree.xpath('//*[@id="react-root"]/section/main/article/header/div[2]/ul/li[2]/a/span')
    following = tree.xpath('//*[@id="react-root"]/section/main/article/header/div[2]/ul/li[3]/a/span')
    
    I can't test this code since I don't have python installed, but it should give you the general idea of what you want to do.

    To find the xpath of an element, just right click an element in chrome dev console and select "Copy XPath"