import ast


def soup_to_script_dict(soup):
    """ Returns dict from inside first 'script' object of instagram page """
    for script in soup.body.find_all('script'):
        if 'is_private' in script.string:
            ret = ast.literal_eval(script.string[20:-1].strip().replace(
                'false', 'False').replace(
                    'true', 'True').replace(
                        'null', "'null'"))
            return ret
    return None