Python PRAW – 获取由 redditor 主持的子版块列表
在 Reddit 中,redditor 是给予用户的术语。版主是负责子版块内容审核的 redditor。在这里,我们将看到如何获取 redditor 正在审核的所有 subreddit。我们将使用Redditor
类的modified moderated()
方法来获取redditor 的审核子reddits 列表。
主持()
Syntax : Redditor.moderated()
Parameter : None
Returns : List of objects of class Subreddit
示例 1:考虑以下 redditor:
redditor 的用户名是:spez。
# importing the module
import praw
# initialize with appropriate values
client_id = ""
client_secret = ""
username = ""
password = ""
user_agent = ""
# creating an authorized reddit instance
reddit = praw.Reddit(client_id = client_id,
client_secret = client_secret,
username = username,
password = password,
user_agent = user_agent)
# the name of the redditor
redditor_name = "spez"
# instantiating the Redditor class
redditor = reddit.redditor(redditor_name)
# fetching the list of moderated subreddits
subreddits = redditor.moderated()
# printing the name of the subreddits
for subreddit in subreddits:
print(subreddit)
输出 :
announcements
blog
programming
HighQualityGifs
OutOfTheLoop
SubredditDrama
business
PartyParrot
modnews
Layer
redditdev
redesign
hero0fwar
reddit_fact_check
yourweek
spez
metaskreddit
hipmunk
guild
modprogramming
示例 2:考虑以下 redditor:
redditor 的用户名是:AutoModerator
# importing the module
import praw
# initialize with appropriate values
client_id = ""
client_secret = ""
username = ""
password = ""
user_agent = ""
# creating an authorized reddit instance
reddit = praw.Reddit(client_id = client_id,
client_secret = client_secret,
username = username,
password = password,
user_agent = user_agent)
# the name of the redditor
redditor_name = "AutoModerator"
# instantiating the Redditor class
redditor = reddit.redditor(redditor_name)
# fetching the list of moderated subreddits
subreddits = redditor.moderated()
# counting the number od subreddits moderated
print(redditor_name + " is a moderator of " + str(len(subreddits)) + " number of subreddits.")
输出 :
AutoModerator is a moderator of 10024 number of subreddits.