我在使用json解析python中的har文件时遇到错误“TypeError:string indices必须是整数”。这是我的代码:
f = open(sys.argv[1], 'r', encoding = "utf8")
global data
data = json.load(f)
f.close()
entries = data["log"]["entries"]
for entry in entries:
url = urlparse(entry["request"]["url"])
domain = url.netloc
entry["domain_name"] = domain
if domain in domain_dict:
domain_dict[domain].extend(entry)
else:
domain_dict[domain] = [entry]
for dom in domain_dict:
for y in domain_dict[dom]:
url_temp = y["request"]["url"]
filetype = y["response"]["content"]["mimeType"]
我在行
中收到错误“TypeError:string indices必须是整数”url_temp = y["request"]["url"]
错误不会出现在循环的每次迭代中。