Skip to content

Instantly share code, notes, and snippets.

@ethanholda
Created June 23, 2017 20:29
Show Gist options
  • Save ethanholda/96856e604aec3106335298461633a276 to your computer and use it in GitHub Desktop.
Save ethanholda/96856e604aec3106335298461633a276 to your computer and use it in GitHub Desktop.
quick instagram workaround 2017-06-23
#!/usr/bin/python
import base64
import re
import requests
import simplejson as json
from bs4 import BeautifulSoup as bs
##########################
instagram_url = 'http://instagram.com'
username = '/nycmarathon'
user_id = '499989070'
num_posts = 1
data = requests.get(instagram_url + username)
soup = bs(data.text)
jssrcs = [x for x in soup.find_all('script') if x.get('src') and '/static/bundles/en_US_Commons.js' in x.get('src')]
if (len(jssrcs) == 1):
jsurl = instagram_url + jssrcs[0].get('src')
jsdata = requests.get(jsurl)
params = {
'query_id': re.findall("(?<=queryId:\")[0-9]{17,17}", jsdata.text)[4],
'id': user_id,
'first': num_posts
}
querydata = requests.get('https://www.instagram.com/graphql/query/', params=params)
print(json.dumps(querydata.json(), indent=2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment