首页 > 解决方案 > 从 JSON 或 XML (WHOIS API) Python 中获取价值

问题描述

我只需要从我读入的 XML/JSON 文件中获取一个值。 https://whoisapi.whoisxmlapi.com/whois/google.com?format=XML

这是我的代码示例:

import json
try:
from urllib.request import urlopen
except ImportError:
from urllib2 import urlopen
domainName = 'google.com';
apiKey = 'YourApiKey'
url = 'https://www.whoisxmlapi.com/whoisserver/WhoisService?'\
+ 'domainName=' + domainName + '&apiKey=' + apiKey + "&outputFormat=JSON"
testing=urlopen(url).read().decode('utf8')
test = json.loads(whoisdb)
registrar = test['WhoisRecord']['registrarName']
domain['whois-created']   = test['WhoisRecord']['createdDate']

如果我稍后使用值“registrar”,我会得到一个“Keyerror”。

不幸的是,其他问题都没有帮助我......

编辑:https ://i.stack.imgur.com/FMBjW.png ,他得到了变量中的值,但我仍然得到这个错误。(我在运行时打印了错误)

标签: pythonjsonxmlwhois

解决方案


推荐阅读