From 886530d66134056ba566ed1248f189419290b7a5 Mon Sep 17 00:00:00 2001 From: naohide <57.x.mas@gmail.com> Date: Fri, 4 Sep 2020 03:20:02 +0900 Subject: [PATCH] Fix wrong ProfileNotExistsException in some edge cases (#785) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes wrong "Profile does not exist" error. Co-authored-by: André Koch-Kramer Co-authored-by: Alexander Graf <17130992+aandergr@users.noreply.github.com> --- instaloader/instaloadercontext.py | 4 ++-- instaloader/structures.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/instaloader/instaloadercontext.py b/instaloader/instaloadercontext.py index ffca86e..a138092 100644 --- a/instaloader/instaloadercontext.py +++ b/instaloader/instaloadercontext.py @@ -351,10 +351,10 @@ class InstaloaderContext: raise ConnectionException("\"window._sharedData\" does not contain required keys.") # If GraphQL data is missing in `window._sharedData`, search for it in `__additionalDataLoaded`. if 'graphql' not in post_or_profile_page[0]: - match = re.search(r'window\.__additionalDataLoaded\([^{]+{"graphql":({.*})}\);', + match = re.search(r'window\.__additionalDataLoaded\(.*?({.*"graphql":.*})\);', resp.text) if match is not None: - post_or_profile_page[0]['graphql'] = json.loads(match.group(1)) + post_or_profile_page[0]['graphql'] = json.loads(match.group(1))['graphql'] return resp_json else: resp_json = resp.json() diff --git a/instaloader/structures.py b/instaloader/structures.py index 430aebb..78219a6 100644 --- a/instaloader/structures.py +++ b/instaloader/structures.py @@ -549,7 +549,7 @@ class Profile: """ # pylint:disable=protected-access profile = cls(context, {'username': username.lower()}) - profile._obtain_metadata() # to raise ProfileNotExistException now in case username is invalid + profile._obtain_metadata() # to raise ProfileNotExistsException now in case username is invalid return profile @classmethod