diff --git a/instaloader/instaloadercontext.py b/instaloader/instaloadercontext.py index 7659af3..ffb326d 100644 --- a/instaloader/instaloadercontext.py +++ b/instaloader/instaloadercontext.py @@ -405,20 +405,13 @@ class InstaloaderContext: raise ConnectionException("HTTP error code {}.".format(resp.status_code)) is_html_query = not is_graphql_query and not "__a" in params and host == "www.instagram.com" if is_html_query: - match = re.search(r'window\._sharedData = (.*);', resp.text) + # Extract JSON from HTML response + match = re.search('(?<={"raw":").*?(?', - resp.text) - if match is not None: - post_or_profile_page[0]['graphql'] = json.loads(match.group(1))['graphql'] + raise QueryReturnedNotFoundException("Could not find JSON data in html response.") + # Unescape escaped JSON string + unescaped_string = match.group(0).encode("utf-8").decode("unicode_escape") + resp_json = json.loads(unescaped_string) return resp_json else: resp_json = resp.json()