From 801640391709eb236d2b818553afed29680a133a Mon Sep 17 00:00:00 2001 From: marco97pa Date: Sun, 28 Feb 2021 12:09:53 +0100 Subject: [PATCH] [Fix] Wrong biography when passing sessionid When a sessionid is passed to the Profile.scrape() function, the scraped profile contains a wrong biography. Instead of getting the biography of the Profile asked, it returns the biography of the account associated to the sessionid (the "viewier user"). The fix maps the key "biography" to "user_biography". This fix is similar to the "profile_pic_url" and "user_profile_pic_url" keys. This is needed beacuse Instagram returns different keys when logged in using a sessionid cookie. Closes #88 --- instascrape/core/_static_scraper.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/instascrape/core/_static_scraper.py b/instascrape/core/_static_scraper.py index 911d284..0e27119 100644 --- a/instascrape/core/_static_scraper.py +++ b/instascrape/core/_static_scraper.py @@ -144,11 +144,14 @@ def scrape( return_data = self._get_json_from_source(self.source, headers=headers, session=session) flat_json_dict = flatten_dict(return_data["json_dict"]) - #HACK: patch mapping to fix the profile pic scrape when a sessionid is present + # HACK: patch mapping to fix the profile pic and biography scrape when a sessionid is present + # When a sessionid is present we should map to the corresponding "user_***" key + # Example: "biography" should be mapped to "user_biography" try: if "sessionid" in headers["cookie"]: mapping["profile_pic_url"] = deque(["user_profile_pic_url"]) mapping["profile_pic_url_hd"] = deque(["user_profile_pic_url_hd"]) + mapping["biography"] = deque(["user_biography"]) except KeyError: pass