我一直在尝试使用Python和PRAW创建一个简单的Reddit机器人。但是,我在从subreddit检索评论时遇到问题。找不到我的“ test_word”,因此我打印了检索到的注释以查看其外观,例如,在这里它们看起来像这五个:
ebkiuyr ebkiuwd ebkiuqe ebkiuoz ebkiue8
由于我收到的字母组合很奇怪,而不是注释,所以我猜我对PRAW的使用不正确吗?
我使用的代码如下:
import praw
import time
processed = []
counter = 0
def run():
# log in
redd = praw.Reddit(client_id = client_id,
client_secret = client_secret,
username = username,
password = password,
user_agent = useragent)
# get comments
for comment in redd.subreddit('testingground4bots').comments(limit=25):
# test to see what comments look like
print(comment)
# reply if phrase found
if "test_word" in comment.body.lower() and comment.id not in processed:
comment.reply("Test successful!")
processed.append(comment.id)
print("replied to comment with id {}".format(comment.id))
while True:
run()
time.sleep(120)