diff --git a/facebook_scraper/extractors.py b/facebook_scraper/extractors.py index acb38b20..b23a10bd 100644 --- a/facebook_scraper/extractors.py +++ b/facebook_scraper/extractors.py @@ -1106,10 +1106,14 @@ def extract_comment_replies(self, replies_url): try: # Some users have to use an AJAX POST method to get replies. # Check if this is the case by checking for the element that holds the encrypted response token - use_ajax_post = self.full_post_html.find("input[name='fb_dtsg']", first=True) is not None + use_ajax_post = ( + self.full_post_html.find("input[name='fb_dtsg']", first=True) is not None + ) if use_ajax_post: - fb_dtsg = self.full_post_html.find("input[name='fb_dtsg']", first=True).attrs["value"] + fb_dtsg = self.full_post_html.find("input[name='fb_dtsg']", first=True).attrs[ + "value" + ] encryptedAjaxResponseToken = re.search( r'encrypted":"([^"]+)', self.full_post_html.html ).group(1) @@ -1121,7 +1125,7 @@ def extract_comment_replies(self, replies_url): else: use_ajax_post = False response = self.request(replies_url) - + except exceptions.TemporarilyBanned: raise except Exception as e: @@ -1140,16 +1144,16 @@ def extract_comment_replies(self, replies_url): break reply_selector = 'div[data-sigil="comment inline-reply"]' - + if self.options.get("noscript"): reply_selector = '#root div[id]' replies = html.find(reply_selector) - + else: # Skip first element, as it will be this comment itself reply_selector = 'div[data-sigil="comment"]' replies = response.html.find(reply_selector)[1:] - + try: for reply in replies: yield self.parse_comment(reply) @@ -1157,7 +1161,7 @@ def extract_comment_replies(self, replies_url): raise except Exception as e: logger.error(f"Unable to parse comment {replies_url} replies {replies}: {e}") - + def extract_comment_with_replies(self, comment): try: result = self.parse_comment(comment) diff --git a/facebook_scraper/facebook_scraper.py b/facebook_scraper/facebook_scraper.py index 91aea351..86273ad8 100755 --- a/facebook_scraper/facebook_scraper.py +++ b/facebook_scraper/facebook_scraper.py @@ -64,7 +64,6 @@ def __init__(self, session=None, requests_kwargs=None): requests_kwargs = {} self.session = session - requests_kwargs["params"] = {"locale": "en_US"} self.requests_kwargs = requests_kwargs def set_user_agent(self, user_agent): @@ -654,7 +653,9 @@ def get_page_info(self, page, **kwargs) -> Profile: ).text except: logger.error("No ld+json element") - likes_and_follows = community_resp.html.find("#page_suggestions_on_liking+div", first=True).text.split("\n") + likes_and_follows = community_resp.html.find( + "#page_suggestions_on_liking+div", first=True + ).text.split("\n") result["followers"] = utils.convert_numeric_abbr(likes_and_follows[2]) except: pass