Eric Krause wrote:
>
> I am new to perl and I am trying to write a script that will allow me to
> automate some tasks that I do every day on the same web pages. Can
> anyone give me some quick examples to get web page data and pass data
> back to the pages?
>
> Sorry if this question is lame, I am new, but trying to learn. Thanks
> for any help!

Hello Eric.

It would help if we knew the sort of thing you wanted to do on the Web. Here's a
taster that uses WWW::Mechanize that others have recommended to interrogate the
CPAN search engine for 'Mechanize' modules. It processes the results using
HTML::TreeBuilder.

Since it may be a long way away from what you want to do I'm offering it without
narrative. I hope it helps.

Rob


use strict;
use warnings;

use WWW::Mechanize;
use HTML::TreeBuilder;

use IO::Handle;
autoflush STDOUT;

my $mech = WWW::Mechanize->new;
$mech->get('http://www.cpan.org/');
$mech->follow_link(text => 'CPAN modules, distributions, and authors');

$mech->field(query => 'Mechanize');
$mech->select(mode => 'Modules');
$mech->click;
show_detail($mech);

while (my $next = $mech->follow_link(text_regex => qr/Next/)) {
  show_detail($mech);
}


sub show_detail {

  my $mech = shift;
  my $tree = HTML::TreeBuilder->new_from_content($mech->content);

  my ($small) = $tree->find('small');
  print $small->as_trimmed_text, "\n\n";

  foreach ($tree->find('p')) {
    my ($a) = $_->find('a');
    print $a->as_trimmed_text, "\n";
  }
  print "\n\n";

  $tree->delete;
}


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to