Domanda

Sto usando la classe difflib.HtmlDiff , chiamando la funzione utilizzando due set di testo (HTML da siti web), ma quando si fa la tabella

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

tuttavia, che sembra appena confrontare char di char (1 carattere per riga tabella), e finire con un file 4.3MB txt per due serie di html che solo 100k sono.

Il file doc dice:

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.

, tuttavia, che non sembra essere il caso.

Qualche suggerimento?

È stato utile?

Soluzione

Si sta fornendo stringhe, non liste di stringhe (righe).

Supponendo UNIX o di Windows estremità della linea:

print html_diff.make_table(previous_contents.split('\n'),
                           fetch_url.page_contents.split('\n'))
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top