Skip to content
Snippets Groups Projects

instagram scraper basic profile

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Jan Maria Kopankiewicz
    ig.py 1.04 KiB
    from requests import get
    from pyquery import PyQuery as pq
    import json
    import datetime
    
    
    
    # Profile as source
    # print out all info
    
    profile = "fraunhofer.karriere"
    url = 'https://www.instagram.com/'+profile
    # dt = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    try:
        doc = pq(get(url).text)
        data = (doc('script')[4].text)[21:-1]
        jdat = json.loads(data)['entry_data']['ProfilePage'][0]['graphql']['user']
    except:
        doc = pq(get(url).text)
        data = (doc('script')[3].text)[21:-1]
        jdat = json.loads(data)['entry_data']['ProfilePage'][0]['graphql']['user']
    
    for key in jdat.keys():
        if key == "edge_owner_to_timeline_media":
            print("{}\n\n{}\n:".format("###############################",key))
            for i in range(0,12):
                for media_key in jdat[key]['edges'][i]['node'].keys():
                    print("{}:\n{}\n".format(media_key,jdat[key]['edges'][i]['node'][media_key]))
            print("###############################\n")
        if key != "edge_owner_to_timeline_media":
            print('{}:\n{}\n'.format(key,jdat[str(key)]))
    0% or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment