Is there a HTML parser who can reconstruct the original html EXACTLY?

Paul Boddie paul at boddie.org.uk
Wed Jan 23 09:07:43 EST 2008


On 23 Jan, 14:20, kliu <ios... at gmail.com> wrote:
>
> Thank u for your reply. but what I really need is the mapping between
> each DOM nodes and the corresponding original source segment.

At the risk of promoting unfashionable DOM technologies, you can at
least serialise fragments of the DOM in libxml2dom [1]:

  import libxml2dom
  d = libxml2dom.parseURI("http://www.diveintopython.org/", html=1)
  print d.xpath("//p")[7].toString()

Storage and retrieval of the original line and offset information may
be supported by libxml2, but such information isn't exposed by
libxml2dom.

Paul

[1] http://www.python.org/pypi/libxml2dom



More information about the Python-list mailing list