我正在寻找一个属性,其中包含提交标题,该属性是提交的固定链接的一部分。不幸的是,根据PRAW文档http://praw.readthedocs.io/en/latest/search.html?q=permalink&check_keywords=yes&area=default
,praw.models.reddit.submission.Submission
似乎不包含permalink
属性
但是,如果我跑
import praw
print(praw.__version__)
reddit = praw.Reddit(...)
for submission in reddit.subreddit("redditdev").hot(limit=5):
print(type(submission), submission.permalink)
我会得到
4.4.0 <class 'praw.models.reddit.submission.Submission'> /r/redditdev/comments/77gz1m/new_mobile_friendly_reddit_search_is_now_in_beta/ <class 'praw.models.reddit.submission.Submission'> /r/redditdev/comments/77dkl6/can_anyone_explain_why_my_if_x_in_y_isnt_working/ <class 'praw.models.reddit.submission.Submission'> /r/redditdev/comments/77ci3v/ratelimit_you_are_doing_that_too_much/ <class 'praw.models.reddit.submission.Submission'> /r/redditdev/comments/77bak9/is_there_some_standard_way_to_host_bots/ <class 'praw.models.reddit.submission.Submission'> /r/redditdev/comments/77ci1v/praw_checking_if_my_bot_has_already_posted_in_a/
因此,即使permalink
在grep
以外的源文件中找不到permalink
,我对comment.py
的调用也能正常工作?!
$ grep -r -i -l "permalink" --include "*.py" /usr/local/lib/python3.6/dist-packages/praw/ /usr/local/lib/python3.6/dist-packages/praw/models/reddit/comment.py
如果您在GitHub上的源代码中搜索permalink
,则与最新版本相同:https://github.com/praw-dev/praw/search?l=Python&q=permalink&type=&utf8=%E2%9C%93
发生了什么事?属性来自何处?
答案 0 :(得分:1)
PRAW动态提供Reddit通过API返回的属性。因为这些属性可能会在Reddit结束时发生变化,所以PRAW不会记录它们,除了指导您如何发现可用内容:
当您遍历reddit.subreddit("redditdev").hot(limit=5)
时,PRAW向https://oauth.reddit.com/r/redditdev/hot/.json?limit=5发出请求,该请求基本上返回与https://www.reddit.com/r/redditdev/hot/.json?limit=5相同的数据。访问后一个链接时,您应该看到永久链接属性出现5次,因为该请求是针对5个提交的。您还将看到提交对象可用的所有其他属性。