praw:在Subreddit中获取随机帖子的身体和标题
我正在尝试将标题与给定子列数随机帖子的内容(正文)一起打印出来。我一直在互联网上四处寻找如何做到这一点,但我似乎无法弄清楚。
我在这里写了一些东西,可以随机提交。
import praw
reddit = praw.Reddit(
client_id = "",
client_secret = "",
password = "",
user_agent = "",
username = "",
)
random_submission = reddit.subreddit('playboicarti').random()
print(random_submission)
示例输出:
v206wo
这里是从称为playboicarti
的子reddit的随机提交的ID。
有人知道我应该如何使用ID打印出标题和该提交内容的内容吗?
I'm trying to print out the title along with the content (body) of a random post on a given subreddit. I've been looking around all over the internet on how to do this, but I cant seem to figure it out.
I've written something down here that gets the id of a random submission.
import praw
reddit = praw.Reddit(
client_id = "",
client_secret = "",
password = "",
user_agent = "",
username = "",
)
random_submission = reddit.subreddit('playboicarti').random()
print(random_submission)
Example output:
v206wo
Here it's getting the id of a random submission from the subreddit called playboicarti
.
Does anyone know how I'm supposed to print out the title and the content of that submission using the id?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以同时访问
标题
属性和url
属性,打印标题并在浏览器中打开URL?关于
url
属性的好处是,它将遵循链接,或在自我/文本帖子的情况下打开帖子。如果要打印文本帖子的上下文或打开链接帖子,则可以访问
自读文本
属性,或像这样打开链接:You can access both the
title
attributes and theurl
attributes, print the title and open the url in a browser perhaps?The nice thing about the
url
attribute is that it will follow the link, or open the post in the case of a self/text post.If you wanted to print the context of a text post OR open a link post, you can access the
selftext
attribute, or open the link like so: