python - Check if user exists with PRAW
问题描述
Is it possible to check if a specified user exists using PRAW, and if so what is the proper way to do so? I couldn't find any builtin functions that do this, so your help would be appreciated.
解决方案
Arnav 的答案仅适用于旧版本的 PRAW(2016 年之前)。如果你开始一个新项目,你应该使用最新版本的 PRAW。在该版本中,这是有效的代码:
import praw
from prawcore.exceptions import NotFound
reddit = praw.Reddit( # authentication goes here
)
def user_exists(name):
try:
reddit.redditor(name).id
except NotFound:
return False
return True
推荐阅读
- android - Android 应用程序包,强制在所有 apk 中包含 ABI
- awk - 仅在出现第二个图案时打印两个图案
- c - System.ServiceModel.CommunicationException: '接收 HTTP 时发生错误
- ruby-on-rails - Capistrano 部署无法访问服务器 ENV 变量,但在服务器上存在 ENV
- sql-server - 是否可以在 SQL Server 中使用 SQL - 显示表 A 中的所有记录,即使
- google-chrome - WebElement.sendKeys(CharSequence...) 通过 Selenium 仅发送部分值
- vba - 从 .txt 导入中删除页眉和页脚
- angular - Angular CLI - 检测库更改以重建消费应用程序
- android - 如何使用可能的待处理意图从服务导航到导航片段?
- angular - 如何在 HTML 字符串中使用 routerLink?