質問

私が使用しているのは、 difflib.HtmlDiff クラスでは、2 つのテキスト セット (Web サイトからの HTML) を使用して関数を呼び出しますが、テーブルを作成するときに

html_diff = difflib.HtmlDiff()
print html_diff.make_table(previous_contents, fetch_url.page_contents)

ただし、これは文字ごとに(テーブル行ごとに1文字)比較しているだけのようで、わずか100kの2つのHTMLセットに対して4.3MBのtxtファイルができてしまいます。

doc ファイルには次のように書かれています。

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.

しかし、そうではないようです。

助言がありますか?

役に立ちましたか?

解決

文字列 (行) のリストではなく、文字列を指定します。

UNIX または Windows の行末が次のようになっていると仮定します。

print html_diff.make_table(previous_contents.split('\n'),
                           fetch_url.page_contents.split('\n'))
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top