Hello Esteemed Monks of Perl,

I have a problem that I have been working on for a couple of days. I'm a new comer to Perl, so I may be missing something obvious, but my searching through the web and documentation has not produced a definitive answer on this.

My problem is I have some string of text ($text) that I know is somewhere in a page of HTML. What I would like to do is search though the HTML for $text and find out what the lowest level element is that contains $text, and be able to find out the ancestors for that element.

I feel like I am in the right arena with HTML::TreeBuilder and HTML::TokeParser, since TreeBuilder maintains the relationships I am looking for while TokeParser make it easy to search for text, but I feel like I need some combination of the two. I also feel like I might be overlooking something obvious in one or the other (I guess I have a lot of feelings.)


In reply to Finding the DOM element via text search by wbushey

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.