Hello wise monks. I know this kind of question has been asked somewhat, and to that many answers have come out, and the use of HTML::TokeParser is a wonderful tool for most of my needs.

I have some more complicated things that I want to do with pages I have consumed and parsed with said module. I would like to use xpath to work with the HTML page that I have consumed, as I do with the XML reports I create/read. The problem I am having is two fold. First, XML::LibXML is ok if there are no ampersands and that the web page is strict. As we all know this is not typical and almost all pages that I come across on client sites are broken to a small degree or use an ampersand.

I have seen a few modules that allow you to access Mozilla/Webkit engines, but seem that they will actually launch a browser instance from what I have read, and this isn't what I want. Ideally I'd like to have the ability to consume a web page into a DOM object with a mainstream parser (Mozilla/Webkit etc) and then be able to extract nodes and objects via xpath, again, as I do with LibXML and XML files.

Thanks in advance for any insight / suggestions


In reply to Parsing HTML Documents by itsscott

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.