python - 从 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 ,他得到了变量中的值,但我仍然得到这个错误。(我在运行时打印了错误)
解决方案
推荐阅读
- javascript - 将EventListener添加到chrome扩展中的所有iframe
- android - 缺少主调度程序的模块
- javascript - 在 JavaScript 中将 Base64 类型转换为字符串
- java - 既然 twitter 禁用了用户/站点流,您如何使用 Twitter4J 收听新的直接消息
- java - OkHttp 不重用 HTTPS/HTTP2 连接
- java - 任务:将 csv、xml 文件导入新的 Schema。显示报告。JAVA
- visual-studio-code - 无法在 VSCode 中跨文件“查找所有引用”的方法/函数
- android - 想在这段代码中添加completionListner但不知道怎么添加以及在哪里添加
- html - “固定” html 元素并不总是相对于视口定位......那么确切的规则是什么?
- java - 使用 @WebMvcTest 进行休息控制器测试,无法为 PagedResources 实例化 JAXBContext