Skip to content
This repository was archived by the owner on Apr 20, 2023. It is now read-only.

Commit e88032e

Browse files
committed
comment fix
1 parent 6e80d92 commit e88032e

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

instascrape/scrapers/post.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,17 @@ def get_recent_comments(self) -> List[Comment]:
228228
comments_arr : List[Comment]
229229
List of Comment objects
230230
"""
231-
list_of_dicts = self.json_dict["entry_data"]["PostPage"][0]["graphql"]["shortcode_media"][
232-
"edge_media_to_parent_comment"
233-
]["edges"]
231+
# HACK:
232+
# The JSON is structured differently if the scrape is performed using a
233+
# WebDriver or Session.
234+
try:
235+
list_of_dicts = self.json_dict["entry_data"]["PostPage"][0]["graphql"]["shortcode_media"][
236+
"edge_media_to_parent_comment"
237+
]["edges"]
238+
except KeyError:
239+
list_of_dicts = self.json_dict["graphql"]["shortcode_media"][
240+
"edge_media_to_parent_comment"
241+
]["edges"]
234242
comments_arr = [Comment(comment_dict) for comment_dict in list_of_dicts]
235243
return comments_arr
236244

0 commit comments

Comments
 (0)