Greetings monks :)

I'm working on a script that will extract content from a webpage. So far WWW::Mechanize seems to be the go to tool to do this. I'm a bit lost though, since there are a few things I'd like to extract into a single HTML document, and I'm not quite sure what differentiates one paragraph from another, i.e I only care about the content in a specific paragraph tag.

Here's what I have so far.
#!/usr/bin/perl -w use strict; use WWW::Mechanize; use WWW::Mechanize::TreeBuilder; my $mech = WWW::Mechanize->new(); WWW::Mechanize::TreeBuilder->meta->apply($mech); $mech->get("http://millercenter.org/president/clinton/oralhistory/roge +r-altman"); # find all <dl> tags my @list = $mech->find('dl'); foreach ( @list ) { print $_->as_HTML(); }

There is nothing wrong with what I have above and it works perfectly fine. My issue though is that the content extracted is only the interview on the website which was originally all we thought we needed. Now I am looking to extract the "introduction" content (which is in a paragraph tag) as well as some sidebar information.

I understand that I can search for p's as opposed to dl's, but how can I write my script so that it only looks for the nth occurrence, meaning that only the paragraph content I'm looking for gives me the output I want.

Lastly, is this doable all in one script? With what I have above, is it possible to tack on the introduction to the dl HTML that gets generated when I run what I have above?

Advice, guidance, help is greatly appreciated. Thank you!


In reply to Extracting specific <p>content</p> using WWW::Mechanize by mserino

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.