From 8bc35cf3a148b97e0c8f8cd238b6ddc1a4b7d995 Mon Sep 17 00:00:00 2001 From: LostXOR <45744247+LostXOR@users.noreply.github.com> Date: Sun, 15 Oct 2023 23:23:25 -0700 Subject: [PATCH] Fixed error when trying to log in due to changes by Instagram (#2088) --- instaloader/instaloadercontext.py | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) 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()