in reply to Re: Re: Re: form posting question
in thread form posting question

The following code worked...
#!/usr/bin/perl -w # this code worked use strict; use WWW::Mechanize; my $url = 'http://www.bluffsdogs.com/agree.asp'; my $robot = new WWW::Mechanize; $robot->get($url); #$robot->form_number(''); #$robot->form_name(''); #$robot->set_fields('radiobutton' => 'true'); #$robot->click(); # Get the reply to my question my $html = $robot->content(); print "$html";
...BUT...

Now I want to be able to parse the results for links. In another program I used something like:
my $response = $browser->get($baseurl,@ns_headers); die "$baseurl error: ", $response->status_line unless $response->is_success; die "Weird content type at $baseurl -- ", $response->content_type unless $response->content_type eq 'text/html'; my $html = $response->content; # save all files that match pattern given - ignore case while( $html =~ m/<a.{1,40}href=(.*?)>/ig ) { my $matchline = $1; #print "matchline = $matchline\n"; if($matchline =~ m/\"(.*?)\"/ig ) { $matchline=$1; $sawcount++; } # else keep what you have $savestr= URI->new_abs( $matchline, $response->base ); #print "savestr = $savestr\n"; if ($savestr =~ /$pattern/i ) {$savecount++;&storeurl($savestr,$ +trackname,$year)}; } print "I saw $sawcount URLs and thought $savecount where of intere +st.\n";
Is it possible use things like $savestr= URI->new_abs( $matchline, $response->base ); with Mechanize???

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: form posting question
by Corion (Patriarch) on May 20, 2004 at 07:10 UTC

    Does the $agent->links method, as found in the WWW::Mechanize documentation not work for you?

    my @links = grep {$_->text /$pattern/i} $agent->links(); for (@links) { storeurl( $_->url, $trackname, $year ); };

    I suggest that you read the WWW::Mechanize documentation, as it contains many helpfull hints about what is possible with WWW::Mechanize.