Python PRAW – 在 Reddit 中清除评论的投票
在 Reddit 中,我们可以对任何提交发表评论,也可以对评论发表评论以创建评论线程。我们可以赞成或反对评论。在这里,我们将看到如何使用 PRAW 从评论中删除赞成票或反对票。我们将使用Comment
类的clear_vote()
方法来清除评论的投票。
clear_vote()
Syntax : clear_vote()
Parameters : None
Returns : Nothing
示例 1:考虑以下评论:
评论的ID是:fvib7aw
# 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 clearing the vote :" + str(comment.score))
# clearing the vote the comment
comment.clear_vote()
print("Score after clearing the vote :" + str(comment.score))
输出 :
Score before upvoting : 25
Score after upvoting : 25
示例 2:考虑以下评论:
评论的ID是:fv9qvgo
# 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 clearing the vote :" + str(comment.score))
# clearing the vote the comment
comment.clear_vote()
print("Score after clearing the vote :" + str(comment.score))
输出 :
Score before upvoting : 4
Score after upvoting : 3
在评论中写代码?请使用 ide.geeksforgeeks.org,生成链接并在此处分享链接。