【发布时间】:2026-02-24 20:20:09
【问题描述】:
我正在编写一个机器人来解析包含特定字符的帖子标题的特定 subreddits。如下所示,在r.subreddit() 方法中,我已经传递了'nba',但还希望机器人解析'nbadiscussion'、'warriors' 和'NYKnicks'。
怎么只抢/r/nba的顶帖?谢谢!
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()
【问题讨论】: