I\'m just starting to learn how to web scrape using BeautifulSoup and want to write a simple program that will get the follower count for a given Instagram
Use the API is the easiest way, but I also found a very hacky way to do it:
import requests
username = "espn"
url = 'https://www.instagram.com/' + username
r = requests.get(url).text
start = '"edge_followed_by":{"count":'
end = '},"followed_by_viewer"'
followers= r[r.find(start)+len(start):r.rfind(end)]
start = '"edge_follow":{"count":'
end = '},"follows_viewer"'
following= r[r.find(start)+len(start):r.rfind(end)]
print(followers, following)
If you look through the response requests gives, theres a line of Javascript that contains the real follower count:
...edge_followed_by":{"count":10770969},"followed_by_viewer":{
...
So I just extracted the number by finding the substring before and after.