What is the difference between etree.XML and etree.HTML?

Hi, In the following example, XML and HTML work equally well. Does anybody has an example showing when they will be different? Thanks. from lxml import etree tree = etree.XML('<foo><bar>abc</bar></foo>') tree = etree.HTML('<foo><bar>abc</bar></foo>') print type(tree) r = tree.xpath('//bar') print [x.tag for x in r] -- Regards, Peng

Am 20.12.2017 um 00:55 schrieb Peng Yu:
from lxml import etree tree = etree.XML('<html><p>abc</html>') print type(tree) r = tree.xpath('//p') print [x.tag for x in r] gives: line 1, column 20 whereas from lxml import etree tree = etree.HTML('<html><p>abc</html>') print type(tree) r = tree.xpath('//p') print [x.tag for x in r] gives

Am 20.12.2017 um 00:55 schrieb Peng Yu:
from lxml import etree tree = etree.XML('<html><p>abc</html>') print type(tree) r = tree.xpath('//p') print [x.tag for x in r] gives: line 1, column 20 whereas from lxml import etree tree = etree.HTML('<html><p>abc</html>') print type(tree) r = tree.xpath('//p') print [x.tag for x in r] gives
participants (2)
-
Markus Schöpflin
-
Peng Yu