PRAW bot only parsing one subreddit when wanted to parse multiple
I'm writing a bot that parses specific subreddits for titles of posts that contain specific characters. As you can see below, in the
r.subreddit() method, I've passed
'nba', but also want the bot to parse
How come it's only grabbing the top posts from
def run_bot(): sub = r.subreddit('nba+nbadiscussion+warriors+NYKnicks') print("Grabbing subreddit") subs = sub.top('year', limit=5) print("Grabbing posts in sub") for posts in subs: article_url = posts.url post_title = posts.title print(post_title) print(article_url) string1 = post_title durantRegex = re.compile(r'[KevinDurantKnicks]') x = durantRegex.search("Kevin Durant Knicks", string1) run_bot()
If you want 5 results from each sub youd be better off using a for loop over a list of subs.
subs_to_search = ['nba', 'nbadiscussion', 'warriors', 'NYKnicks'] for sub_name in subs_to_search: sub = r.subreddit(sub_name) subs = sub.top('year', limit=5) for posts in subs: article_url = posts.url post_title = posts.title print(post_title) print(article_url)
So on and so forth, so you're doing an action for each sub. It'll get 5 from each, do what you need it to do, then move to the next subreddit Hope that helps.
Comment Parsing — PRAW 3.6.2 documentation, Note that this may include MoreComments objects and not just Comment . So we test the bot in r/test before we let it loose on a “real” subreddit. Replacing all MoreComments in a thread with many comments will require many API calls and so take Reddit('Comment parser example by u/_Daimon_') >>> all_comments � Submission Stream Reply Bot¶. Most redditors have seen bots in action on the site. Reddit bots can perform a number of tasks including providing useful information, e.g., an Imperial to Metric units bot; convenience, e.g., a link corrector bot; or analytical information, e.g., redditor analyzer bot for writing complexity.
This is because the
limit=5 you've specified in
subs = sub.top('year', limit=5) is limiting your result set from the combined subreddits to just five results altogether.
Try upping the
limit parameter or removing it altogether to see results from the other subreddits as well.
Comment Extraction and Parsing — PRAW 7.1.1.dev0 documentation, If you instead want process all comments on Reddit, or comments belonging to one or more specific subreddits, please see praw.models.reddit.subreddit. If we wanted to output only the body of the top level comments in the thread we could do: and parse all (or most) of the comments belonging to a single submission. If you are only analyzing public comments, entering a username and password is optional. In this document we will detail the process of finding all the comments for a given submission. If you instead want process all comments on Reddit, or comments belonging to one or more specific subreddits, please see praw.models.reddit.subreddit
Submission Stream Reply Bot — PRAW 7.1.1.dev0 documentation, Reddit bots can perform a number of tasks including providing useful https:// lmgtfy.com/?q=How+many+feet+are+in+a+yard%3F To register an application and receive a set of OAuth2 credentials please follow only the “First Steps” section of Replace AskReddit with the name of another subreddit if you want to iterate� 2 PRAW bot only parsing one subreddit when wanted to parse multiple May 14 '19. 2 Python - Converting XLSX to PDF Jun 11 '19. View all questions and answers →
Subreddit — PRAW 7.1.1.dev0 documentation, Multiple subreddits can be combined with a + like so: for submission in reddit. subreddit("redditdev+learnpython").top("all"): print(submission). Subreddits can be� The PRAW automatically handles your request limit, so you shouldn't need to worry about breaching the rules. The only thing you might want to note is that the PRAW is not thread-safe. Alright, so let's see an example for both the comments.list() and replace_more() functionalities:
The Reddit Instance — PRAW 7.1.1.dev0 documentation, If you want to obtain the comment's replies, you will need to call refresh() on the returned Comment . Return parsed objects returned from a DELETE request to path . At present only new LiveThreads can be created. Note that multiple subreddits can be combined and filtered views of r/all can also be used just like a � Comment Parsing¶ A common task for many bots and scripts is to parse a submission´s comments. In this tutorial we will go over how to do that as well as talking about comments in general. To illustrate the problems, we’ll write a small script that replies to any comment that contains the text “Hello”.
I wrote a bot in python 3 using PRAW, requests, and BeautifulSoup that downloads a specified amount of image posts from a specified subreddit. One limitation is that it can only parse the direct image link from imgur pages, but I am not too bent on figuring them out because the majority of image posts on reddit are from imgur, and I don't care
- This is not the case. The top 100+ posts in the listing OP is searching through are all from /r/nba because /r/nba is more popular and so has posts with higher scores.
- Thanks for the thorough explanation. I had lacked understanding of how the praw API wrapper works.