creat a DOM from an html document

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mark Harrison

    #1

    creat a DOM from an html document

    I thought I saw a package that would create a DOM from html, with
    allowances that it would do a "best effort" job to parse
    non-perfectly formed html.

    Now I can't seem to find this... does anybody have a recommendation
    as to a good package to look at?

    Many TIA!
    Mark
  • Mark Harrison

    #2
    Re: creat a DOM from an html document

    Mark Harrison <mh@pixar.com > wrote:[color=blue]
    > Now I can't seem to find this... does anybody have a recommendation
    > as to a good package to look at?[/color]

    Ahh, it's BeautifulSoup.. .

    Thanks All!!

    Comment

    • John J. Lee

      #3
      Re: creat a DOM from an html document

      Mark Harrison <mh@pixar.com > writes:
      [color=blue]
      > Mark Harrison <mh@pixar.com > wrote:[color=green]
      > > Now I can't seem to find this... does anybody have a recommendation
      > > as to a good package to look at?[/color]
      >
      > Ahh, it's BeautifulSoup.. .[/color]

      Strictly that's not THE DOM, just A document object model. The DOM
      proper is a standardised interface, which BeautifulSoup does not
      implement. You could build a DOM using BeautifulSoup, though.


      John

      Comment

      • Paul Boddie

        #4
        Re: creat a DOM from an html document

        John J. Lee wrote:[color=blue]
        > Mark Harrison <mh@pixar.com > writes:
        >[color=green]
        > > Ahh, it's BeautifulSoup.. .[/color]
        >
        > Strictly that's not THE DOM, just A document object model. The DOM
        > proper is a standardised interface, which BeautifulSoup does not
        > implement. You could build a DOM using BeautifulSoup, though.[/color]

        For a certain value of standardised, libxml2dom provides "the DOM" for
        HTML:

        import urllib, libxml2dom
        f = urllib.urlopen( "http://www.python.org" )
        s = f.read(); f.close()
        d = libxml2dom.pars eString(s, html=1)
        print "There are", len(d.xpath("//table")), "tables in the document."

        See http://www.python.org/pypi/libxml2dom for more information.

        Paul

        Comment

        • Xavier Morel

          #5
          Re: creat a DOM from an html document

          Mark Harrison wrote:[color=blue]
          > I thought I saw a package that would create a DOM from html, with
          > allowances that it would do a "best effort" job to parse
          > non-perfectly formed html.
          >
          > Now I can't seem to find this... does anybody have a recommendation
          > as to a good package to look at?
          >
          > Many TIA!
          > Mark[/color]
          While it doesn't generate a W3C DOM, BeautifulSoup is probably your best
          bet for parsing less-than-perfect HTML and get something useable out of it.

          Once you have your (parsed) document, you can either use it as is or try
          to convert it to a valid W3C DOM though.

          Comment

          Working...