En Reddit, podemos publicar un comentario en cualquier envío, también podemos comentar un comentario para crear un hilo de comentarios. Cada comentario tiene un hipervínculo estático permanente asociado. Aquí veremos cómo obtener el enlace permanente de un comentario usando PRAW. Usaremos el permalink
atributo de la Comment
clase para obtener el enlace permanente de un comentario.
Ejemplo 1: Considere el siguiente comentario:
El ID del comentario es: 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) # fetching the permalink attribute permalink = comment.permalink print("The permalink of the comment is : \n" + permalink) print("\nThe complete URL of the comment is : \n" + "https://www.reddit.com/" + permalink)
Producción :
The permalink of the comment is : /r/aww/comments/hczt0c/i_got_adopted_by_this_beautiful_pup_this_weekend/fvib7aw/ The complete URL of the comment is : https://www.reddit.com//r/aww/comments/hczt0c/i_got_adopted_by_this_beautiful_pup_this_weekend/fvib7aw/
Ejemplo 2: Considere el siguiente comentario:
El ID del comentario es: 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) # fetching the permalink attribute permalink = comment.permalink print("The permalink of the comment is : \n" + permalink) print("\nThe complete URL of the comment is : \n" + "https://www.reddit.com/" + permalink)
Producción :
The permalink of the comment is : /r/redditdev/comments/hbjhnk/reddit_announces_an_upcoming_overhaul_of_how_bots/fv9qvgo/ The complete URL of the comment is : https://www.reddit.com//r/redditdev/comments/hbjhnk/reddit_announces_an_upcoming_overhaul_of_how_bots/fv9qvgo/