<jupyter_start><jupyter_text>This code crawls Instagram accounts and store information on bio, follows, followers, amount of posts, last 100 posts, and last 100 comments for each of posts retrieved. Then the info can be stored and viewed as JSON.<jupyter_code>#DEPENDENCIES
from instaparser.agents import AgentAccount
from instaparser.entities import Account, Media, Location, Tag, Comment
import instagram_explore as ie

#signup in your account AgentAccount("username", "password")
agent = AgentAccount("username", "password")

#all information is stored in this dict
data = dict()

#what users to parse. Set account names followed after this https://www.instagram.com/TARGET_ACCOUNT_NAME/
accounts = ["SET_ACCOUNT_NAME", "SET_ACCOUNT_NAME"]

#process
for account_name in accounts:

    account = Account(account_name)
    
    agent.update(account)
    
    data[account_name] = []

#general info
    data[account_name].append({'biography' : account.biography})
    
    data[account_name].append({'follows' : account.follows_count})
    
    data[account_name].append({'followers' : account.followers_count})
    
    data[account_name].append({'amount_of_posts' : account.media_count})
    
    data[account_name].append({'100_posts' : []})

#post specific info
    
    if account.media_count >= 100:
        media, pointer = agent.get_media(account, count=100)
    else:
        media, pointer = agent.get_media(account, count=int(account.media_count))
    c = 0
    
    for url_media in media:
        
        data[account_name][-1]['100_posts'].append({'post#' + str(c) : [] })
        
        data[account_name][-1]['100_posts'][c]['post#' + str(c)].append({'url' : 'https://www.instagram.com/p/' + str(url_media) })
        
        data[account_name][-1]['100_posts'][c]['post#' + str(c)].append({'caption' : url_media.caption })
        
        data[account_name][-1]['100_posts'][c]['post#' + str(c)].append({'likes' : url_media.likes_count })
        
        data[account_name][-1]['100_posts'][c]['post#' + str(c)].append({'comments' : [] })
        
        res = ie.media(str(url_media))
        
        if url_media.comments_count < 100:
            
            for i in res.data['edge_media_to_comment']['edges']:
                data[account_name][-1]['100_posts'][c]['post#' + str(c)][-1]['comments'].append(i['node']['text'])
#                 print(i['node']['owner']['username'])
        else:
            for i in range(100):
                
                data[account_name][-1]['100_posts'][c]['post#' + str(c)][-1]['comments'].append(res.data['edge_media_to_comment']['edges']
                                                                           [i]['node']['text'])
        c += 1

# write in JSON
import json

with open('data.txt', 'w') as outfile:  
    json.dump(data, outfile)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15487035739313246, 'fraction_numerical': 0.01857042747021724, 'mean_word_length': 3.0727532097004278, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '507117', 'license': 'MIT', 'n_tokens_mistral': 921, 'n_tokens_neox': 874, 'n_words': 174, 'path': 'Instagram_parser_working.ipynb', 'repo_name': 'NikitaNaychukov/Instagram-Parser', 'size': '2854'}