Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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?

You're supplying strings, not lists of strings (lines).

Assuming UNIX or Windows line ends:

print html_diff.make_table(previous_contents.split('\n'),
                           fetch_url.page_contents.split('\n'))
                Your answer was useful to me thank you. Do you know how we can reduce width of output diff (it shows a very wide width of both first and second file) ?
– msashish
                Jul 12, 2020 at 3:40
                @msashish That sounds like an unrelated question. Go ask it! If you want, you can drop me an email or message with the URL.
– phihag
                Jul 12, 2020 at 8:07
                I found the answer. Constructor difflib.HtmlDiff() can take wrapcolumn parameter..thanks anyways
– msashish
                Jul 16, 2020 at 7:11
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.