Skip to content

Instantly share code, notes, and snippets.

@khaledadrani
Last active December 13, 2021 09:15
Show Gist options
  • Save khaledadrani/a661591844b4308aeaefbbd49952641b to your computer and use it in GitHub Desktop.
Save khaledadrani/a661591844b4308aeaefbbd49952641b to your computer and use it in GitHub Desktop.
starter code for praw python
for post in subreddit.hot(limit=5):
print(post.title)
print()
import pandas as pd
posts = subreddit.top("month")
# Scraping the top posts of the current month
posts_dict = {"Title": [], "Post Text": [],
"ID": [], "Score": [],
"Total Comments": [], "Post URL": []
}
for post in posts:
# Title of each post
if post.link_flair_text == "Industry News":
posts_dict["Title"].append(post.title)
# Text inside a post
posts_dict["Post Text"].append(post.selftext)
# Unique ID of each post
posts_dict["ID"].append(post.id)
# The score of a post
posts_dict["Score"].append(post.score)
# Total number of comments inside the post
posts_dict["Total Comments"].append(post.num_comments)
# URL of each post
posts_dict["Post URL"].append(post.url)
# Saving the data in a pandas dataframe
top_posts = pd.DataFrame(posts_dict)
top_posts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment