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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |