📌  相关文章
📜  Python PRAW – 在 Reddit 上点赞评论

📅  最后修改于: 2022-05-13 01:54:22.448000             🧑  作者: Mango

Python PRAW – 在 Reddit 上点赞评论

在 Reddit 中,我们可以对任何提交发表评论,也可以对评论发表评论以创建评论线程。我们可以赞成或反对评论。在这里,我们将看到如何使用 PRAW 对评论进行投票。我们将使用 Comment 类的 upvote() 方法对评论进行投票。

赞成()

示例 1:考虑以下评论:

评论的ID是:fvib7aw

Python3
# 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 ID of the comment
comment_id = "fvib7aw"
 
# instantiating the Comment class
comment = reddit.comment(comment_id)
 
print("Score before upvoting : " + str(comment.score))
 
# upvoting the comment
comment.upvote()
   
print("Score after upvoting : " + str(comment.score))


Python3
# 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 ID of the comment
comment_id = "fv9qvgo"
 
# instantiating the Comment class
comment = reddit.comment(comment_id)
 
print("Score before upvoting : " + str(comment.score))
 
# upvoting the comment
comment.upvote()
   
print("Score after upvoting : " + str(comment.score))


输出 :

Score before upvoting : 25
Score after upvoting : 26

示例 2:考虑以下评论:

评论的ID是:fv9qvgo

Python3

# 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 ID of the comment
comment_id = "fv9qvgo"
 
# instantiating the Comment class
comment = reddit.comment(comment_id)
 
print("Score before upvoting : " + str(comment.score))
 
# upvoting the comment
comment.upvote()
   
print("Score after upvoting : " + str(comment.score))

输出 :

Score before upvoting : 4
Score after upvoting : 5