【问题标题】:How to compare two html files and show only the differences in a new html file using python如何使用python比较两个html文件并仅显示新html文件中的差异
【发布时间】:2019-01-11 15:58:35
【问题描述】:

我使用了 difflib,但 html_table 行需要永远执行。

import difflib

html_1 = data1
html_2 = data2

htmldiff = difflib.HtmlDiff()
html_table = htmldiff.make_table([html_1], [html_2])

我尝试过 htmldiffer,但它给了我 ValueError: stat: path too long for Windows

from htmldiffer import diff

str_a = data1
str_b = data2
d = diff.HTMLDiffer(data1, data2)

print(d.combined_diff)

我已经尝试过 htmltreediff 它给出了 NameError: name 'basestring' is not defined

from htmltreediff import diff
print (diff(data1, data2 , pretty=True))

【问题讨论】:

  • 能否提供完整的错误跟踪?

标签: python html python-3.x python-2.7 difflib


【解决方案1】:

这是使长文件路径在 Windows 上可用的方法: https://www.howtogeek.com/266621/how-to-make-windows-10-accept-file-paths-over-260-characters/

与 difflib 相关的 CPython 问题:

长块的解决方案是将它们分成更小的部分,然后 分别处理。这样二次时间会更小,我们 仍然可以从 _fancy_helper 逻辑中受益。

htmltreediff - 不支持 python 3

【讨论】:

  • 我已经按照“这是如何在 Windows 上使长文件路径可用”的步骤进行了更改。仍然显示相同的错误。
  • @Sushmitha 你重启电脑了吗?
猜你喜欢
  • 1970-01-01
  • 2021-12-11
  • 2015-08-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-06
  • 1970-01-01
相关资源
最近更新 更多