我有两个由sonar生成的html报告,显示了我代码中的问题。在
问题陈述:我需要比较两个声纳报告,找出差异,即引入的新问题。基本上需要找到html中的差异并只打印这些差异。在
我没试过什么-
import difflib
file1 = open('sonarlint-report.html', 'r').readlines()
file2 = open('sonarlint-report_latest.html', 'r').readlines()
htmlDiffer = difflib.HtmlDiff()
htmldiffs = htmlDiffer.make_file(file1, file2)
with open('comparison.html', 'w') as outfile:
outfile.write(htmldiffs)
现在这给了我一个比较.html它只不过是两个html diff。不会只打印不同的行。在
我是否应该尝试HTML解析,然后以某种方式将差异只打印出来?请提出建议。在
如果使用
difflib.Differ
,则只能保留差异行,并使用每行上写入的两个字母代码进行过滤。从docs:通过保持这些行以“-”和“+”开头,只是区别。在
我将首先尝试逐行遍历每个html文件,并检查这些行是否相同。在
您将不得不在一行中处理换行符和多行差异,但这可能是一个好的开始:)
相关问题 更多 >
编程相关推荐