add scraper for Reddit

This commit is contained in:
tsuky_chen
2023-12-20 15:53:07 +08:00
parent 8faba1c8ee
commit 70c04d3270
2 changed files with 1255 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
import praw
def search_reddit(keyword, subreddit, client_id, client_secret, user_agent, limit=10000):
# Initialize PRAW with your Reddit application credentials
reddit = praw.Reddit(client_id=client_id,
client_secret=client_secret,
user_agent=user_agent)
# Search the specified subreddit for the keyword
results = reddit.subreddit(subreddit).search(keyword, limit=limit)
for post in results:
print(f"Title: {post.title}")
print(f"URL: {post.url}")
print(f"Score: {post.score}")
print(f"Comments: {post.num_comments}")
print("------------------------")
# Example usage
if __name__ == "__main__":
CLIENT_ID = 'YOUR_CLIENT_ID'
CLIENT_SECRET = 'YOUR_CLIENT_SECRET'
USER_AGENT = 'my_reddit_scraper'
keyword = "how to"
subreddit = "vscode"
search_reddit(keyword, subreddit, CLIENT_ID, CLIENT_SECRET, USER_AGENT)

File diff suppressed because it is too large Load Diff