Created
January 10, 2022 18:54
-
-
Save pplanel/8f481c506340aafbfa2701417968dd20 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import instaloader | |
import pandas | |
L = instaloader.Instaloader() | |
processed = 0 | |
posts_id = ["CX15pmeJyTD", "CX1yxTPorZi", "CX7GVforxlr"] | |
data = [] | |
if __name__ == '__main__': | |
L.load_session_from_file("demetriusdesbravadata") | |
for p in posts_id: | |
post = instaloader.Post.from_shortcode(L.context, p) | |
comments_count = post.comments | |
for comments in post.get_comments(): | |
data.append({ | |
"id": comments.id, | |
"username": comments.owner.username, | |
"text": comments.text, | |
"likes": comments.likes_count, | |
"timestamp": comments.created_at_utc | |
}) | |
processed += 1 | |
print(f"Processed {processed} of {comments_count} of post {p}\n") | |
df = pandas.DataFrame(data, columns=["id", "username", "text", "likes", "timestamp"]) | |
df.to_csv(f"output_{p}.csv") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment