add scraper for Reddit
This commit is contained in:
28
resouce_collection/Reddit/vscode/get_vscode.py
Normal file
28
resouce_collection/Reddit/vscode/get_vscode.py
Normal 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)
|
||||
1227
resouce_collection/Reddit/vscode/result.txt
Normal file
1227
resouce_collection/Reddit/vscode/result.txt
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user