我试图从JSON字符串中获取恶意值。
获得这个价值的直接方法是什么?截图和下面的代码。
巴斯丁:链接
截图:

import json
def vt(domain):
# load json content from file
with open('vt.txt', 'r') as file:
content = file.read()
# convert from sring to json
content = json.loads(content)
# read how many engines detect this domain as malicious
malicious = content["data"]["attributes"]["last_analysis_stats"]["malicious"]
vt("pp-alert.com")Repl.it代码:https://repl.it/@MiguelDuarte1/ButteryCanineDonateware
发布于 2020-10-17 20:20:13
import json
def vt(domain):
# load json content from file
with open('vt.txt', 'r') as file:
content = file.read()
# convert from sring to json
content = json.loads(content)
# read how many engines detect this domain as
malicious = content['data'][0]['attributes']['last_analysis_stats']['malicious']
#print(malicious)
vt("pp-alert.com")这会给你结果。
注意:您提供的Pastebin链接中的JSON与您在vt.txt文件中实际使用的JSON不同。
发布于 2020-10-17 19:48:37
我认为您错过了一个字段,您不需要[0],因为attributes不是数组。
请尝试:
malicious = content['data']['attributes']['last_analysis_stats']['malicious']https://stackoverflow.com/questions/64406634
复制相似问题