我在具有以下结构的 .txt 文件中获得了一个数据库:
['http://legionanime.com/anime/blazblue-alter-memory.html - BlazBlue Alter Memory', 'http://1.bp.blogspot.com/-5d1npGAZFEQ/Ul_DbUa3MNI/AAAAAAAAP70/wAyDB9E7o9U/s1600/images.jpg - BlazBlue Alter Memory', 'http://legionanime.com/anime/blazblue-alter-memory.html - BlazBlue Alter MemoryBlazBlue Alter Memory', 'http://legionanime.com//.htmlAño de emision: ']
['http://legionanime.com/anime/gundam-build-fighters.html - Gundam Build Fighters', 'http://2.bp.blogspot.com/-My_c7nCIx5M/Ul24Wo16H6I/AAAAAAAAP7M/zwPbKSVAlC8/s1600/descarga+(1).jpg - Gundam Build Fighters', 'http://legionanime.com/anime/gundam-build-fighters.html - Gundam Build FightersGundam Build Fighters', 'http://legionanime.com//.htmlAño de emision: ']
这段代码应该可以工作,但不能。
print("starting")
leyendo = open("myfile.txt", "r")
readed = leyendo.read()
leyendo.close()
if not "[" in str(readed):
print("File got wrong structure")
else:
print("trying to load lines")
with open("myfile.txt", 'r') as readinglines:
for line in readinglines:
print(line) #this one works
lineaactual = json.loads(line) #only if this one doesn't exists. Here is the Error
readinglines.close()
print("Completed")
我得到的错误是“ValueError: No JSON object could be decoded”,我不知道为什么。
该数据库是从使用此函数修复的 html 原始代码创建的:
leidofixed = leido.replace('<div class="cont_anime"><div class="anime_box"><a href="', "['")
leidofixed = leidofixed.replace('" title="', " - ")
leidofixed = leidofixed.replace('"><img id="img2" src="', "', '")
leidofixed = leidofixed.replace('" alt="', " - ")
leidofixed = leidofixed.replace('"></a><div></div><span><h1><a href="', "', '")
leidofixed = leidofixed.replace('</a></h1></span><span2><a href="', "', '")
leidofixed = leidofixed.replace('</a></span2></div></div>', "']\n")
leidofixed = leidofixed.replace('">', "")
我做错了什么?