python读取txt错误_读取.txt文件时出现无效的JSON格式错误

我有一个python脚本,在这个脚本中,我试图读取目录中的所有.txt文件,并确定它们对于脚本中的任何条件是否返回True或False。我有数千个.txt文件,其中有.json格式的文本。但是,我收到一条错误消息,说invalid.json格式。我已经检查了我的文本文件是否为.json格式。我希望脚本确定.txt文件是否与下面代码中的任何语句匹配。然后我想将结果输出到csv文件。非常感谢你的帮助!我已经包括了我的错误消息和example.txt文件。在

带有.json格式的Example.txt文件{

"domain_siblings": [

"try.wisebuygroup.com.au",

"www.wisebuygroup.com.au"

],

"resolutions": [

{

"ip_address": "34.238.73.135",

"last_resolved": "2018-04-22 17:59:05"

},

{

"ip_address": "52.0.100.49",

"last_resolved": "2018-06-24 17:05:06"

},

{

"ip_address": "52.204.226.220",

"last_resolved": "2018-04-22 17:59:06"

},

{

"ip_address": "52.22.224.230",

"last_resolved": "2018-06-24 17:05:06"

}

],

"response_code": 1,

"verbose_msg": "Domain found in dataset",

"whois": null

}

错误消息

^{pr2}$

编码import os

import json

import csv

path=r'./output/'

csvpath='C:/Users/xxx/Documents/csvtest'

file_n = 'file.csv'

def vt_result_check(path):

vt_result = False

for filename in os.listdir(path):

with open(path + filename, 'r') as vt_result_file:

vt_data = json.load(vt_result_file)

# Look for any positive detected referrer samples

# Look for any positive detected communicating samples

# Look for any positive detected downloaded samples

# Look for any positive detected URLs

sample_types = ('detected_referrer_samples', 'detected_communicating_samples',

'detected_downloaded_samples', 'detected_urls')

vt_result |= any(sample['positives'] > 0 for sample_type in sample_types

for sample in vt_data.get(sample_type, []))

# Look for a Dr. Web category of known infection source

vt_result |= vt_data.get('Dr.Web category') == "known infection source"

# Look for a Forecepoint ThreatSeeker category of elevated exposure

# Look for a Forecepoint ThreatSeeker category of phishing and other frauds

# Look for a Forecepoint ThreatSeeker category of suspicious content

threats = ("elevated exposure", "phishing and other frauds", "suspicious content")

vt_result |= vt_data.get('Forcepoint ThreatSeeker category') in threats

return str(vt_result)

if __name__ == '__main__':

with open(file_n, 'w') as output:

for i in range(vt_result_file):

output.write(vt_result_file, vt_result_check(path))

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值