python - 对 Reddit 进行 api 调用时出现 404 错误

标签 python reddit

根据他们的documentation :

这应该足以获得 HitTest 门的新 Reddit 提交内容:

r = client.get(r'http://www.reddit.com/api/hot/', data=user_pass_dict)

但事实并非如此,我收到了 404 错误。我获取数据请求的 url 是否错误?

http://www.reddit.com/api/login 可以工作。

最佳答案

您的问题具体询问您需要做什么才能获得“ HitTest 门的新”提交内容。 “ HitTest 门的新”并没有真正意义,因为存在“热门” View 和"new" View 。这两个 View 的 URL 分别为 http://www.reddit.com/hothttp://www.reddit.com/new

为了使这些 URL 更适合代码,您可以将 .json 附加到 URL(任何 Reddit URL)的末尾,以获取数据的 json 表示形式。例如,要获取“热门”提交的列表,请向 http://www.reddit.com/hot.json 发出 GET 请求。

<小时/>

为了完整起见,在您的示例中,您尝试传入 data=user_pass_dict。这绝对不会按照您期望的方式工作。虽然登录对于您想做的事情来说并不是必需的,但如果您碰巧需要使用 python 来更复杂地使用 reddit 的 API,我强烈建议使用 PRAW 。使用 PRAW,您可以通过以下方式迭代“热门”提交:

import praw
r = praw.Reddit('<REPLACE WITH A UNIQUE USER AGENT>')
for submission in r.get_frontpage():
    # do something with the submission
    print(vars(submission))

关于python - 对 Reddit 进行 api 调用时出现 404 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16093525/

相关文章:

python - PRAW:获得用户的天赋

python - Instagram API 在 follow_user(user_id) 上失败

python - 获取当前选中的 QTreeView 项的文本和索引

python - 如何在使用 djanago-allauth 发出 post_save 信号后发送电子邮件确认邮件

Python 拆分数组使用 For 循环来表示每个拆分并将其重新组合在一起

python - 我如何使用 PRAW 列出 subreddit 中的热门评论?

python - 使用 python PRAW 提取 reddit 评论并使用结果创建数据框

javascript - 如何更改 reddit 的嵌入评论 iframe 的最大宽度?

python - 在 Python 中为道琼斯指数抓取雅虎财经

PHP Reddit 排名算法 - 计算排名