使用 difflib.HtmlDiff 类 - 显示单个字符
我正在使用 difflib.HtmlDiff
类,使用两组文本(来自网站的 HTML)调用该函数,但是当它创建表格时
html_diff = difflib.HtmlDiff()
print html_diff.make_table(previous_contents, fetch_url.page_contents)
,似乎只是逐个字符进行比较(每个表格行 1 个字符),最终得到一个 4.3MB 的 txt两套html文件,只有100k。
文档文件说,
Compares fromlines and tolines (lists of strings) and returns a string which is a
complete HTML file containing a table showing line by line differences with
inter-line and intra-line changes highlighted.
但情况似乎并非如此。
有什么建议吗?
I am using the difflib.HtmlDiff
class, calling the function using two sets of text (HTML from websites), however when it makes the table
html_diff = difflib.HtmlDiff()
print html_diff.make_table(previous_contents, fetch_url.page_contents)
however that just seems to compare char by char (1 char per table row), and I end up with a 4.3MB txt file for two sets of html which are only 100k.
The doc file says,
Compares fromlines and tolines (lists of strings) and returns a string which is a
complete HTML file containing a table showing line by line differences with
inter-line and intra-line changes highlighted.
however that doesn't seem to be the case.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您提供的是字符串,而不是字符串(行)列表。
假设 UNIX 或 Windows 行结束:
You're supplying strings, not lists of strings (lines).
Assuming UNIX or Windows line ends: