Help: Scrape Insta Followers using Python

Chris B

Newbie
Joined
Jun 29, 2017
Messages
26
Reaction score
2
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
 
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"
 
Back
Top