28 lines
945 B
Python
28 lines
945 B
Python
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) |