python:compare
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
python:compare [2014/07/22 08:17] – [Get matching blocks] admin | python:compare [2022/10/29 16:15] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 371: | Line 371: | ||
* etree for parsing HTML | * etree for parsing HTML | ||
Examples for lxml.html.diff: | Examples for lxml.html.diff: | ||
- | * Simple diff HTML:< | + | * Simple diff:<code python> |
+ | from os import path | ||
+ | import sys, re | ||
+ | from lxml.html import diff, etree, HTMLParser | ||
+ | import codecs | ||
+ | import StringIO | ||
+ | doc1 = '''< | ||
+ | <div class=" | ||
+ | <a title=" | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | <div class=" | ||
+ | <a class=" | ||
+ | <i class=" | ||
+ | < | ||
+ | </ | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | doc2 = '''< | ||
+ | <div class=" | ||
+ | <a title=" | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | <div class=" | ||
+ | <a class=" | ||
+ | <i class=" | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | diffcontent = diff.htmldiff(doc1, | ||
+ | diffcontent = codecs.encode(diffcontent, | ||
+ | print diffcontent | ||
+ | </ | ||
+ | <div class=" | ||
+ | </ | ||
+ | * diff 2 HTML files:<code python> | ||
from os import path | from os import path | ||
import sys, re | import sys, re |
python/compare.1406017061.txt.gz · Last modified: 2022/10/29 16:15 (external edit)