Skip to content

Instantly share code, notes, and snippets.

@seunggabi
Created March 31, 2020 04:59
Show Gist options
  • Save seunggabi/a4fde805d7360e91272758718e55629a to your computer and use it in GitHub Desktop.
Save seunggabi/a4fde805d7360e91272758718e55629a to your computer and use it in GitHub Desktop.
instagram_follower.py
import requests
from bs4 import BeautifulSoup
import json
import sys
from datetime import datetime
# window._sharedData.entry_data.ProfilePage[0].graphql.user.edge_followed_by.count
try:
id = sys.argv[1]
except IndexError:
id = "seunggabi.kim"
url = "https://www.instagram.com/"+id+"/"
source_code = requests.get(url)
source_code.encoding = "utf-8"
contents = source_code.text
soup = BeautifulSoup(contents, "html.parser")
# mainEntityofPage.interactionStatistic.userInteractionCount
target = soup.find("script", {"type": "application/ld+json"})
info = json.loads(target.text)
count = info['mainEntityofPage']['interactionStatistic']['userInteractionCount'];
print(datetime.now().isoformat()+" "+count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment