Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

screen scraping MECHANIZE

by garskoci (Novice)
on Feb 05, 2005 at 14:41 UTC ( #428322=perlquestion: print w/replies, xml ) Need Help??
garskoci has asked for the wisdom of the Perl Monks concerning the following question:

Hello! This is a repost of a problem that I just can get straightened out. I am trying write a Perl script to log into my router and open and close ports. I am able to log and and move around. I and able to retrieve data like IP address etc. But not able to check a checkbox or uncheck a checkbox. There are no errors, it just doesn't seem to update the checkboxes. As you can see from the code I have tried a few different things, without any luck though. I think that this is the HTML that I am working with.
<td width="10%" align="center"><input type="checkbox" name="EnBt0" val +ue="checkbox" CHECKED > </td>
Can anyone help? Thanks.
#!/usr/bin/perl use strict; use warnings; use WWW::Mechanize; my $url=''; my $lo_url=''; my $mech = WWW::Mechanize->new( utocheck => 1 ); $mech->credentials( '', 'FVS318', 'admin' => 'secret' ); # And then $mech->get() the same as in the LWP::UserAgent code my $response = $mech->get($url); die "Error at $url\n ", $response->status_line, "\n Aborting" unless $ +response->is_success; print "SUCCESS data type: ", $response->content_type, "\n\n"; #print "\n\n"; #print $response->content; $mech->tick('EnBt3', 'checkbox', 'CHECKED'); #$mech->current_form->POST( submit => { name => "Apply ", value =>"sub +mit" } ); #$mech->click_button(number => 2); #$mech->submit(); #$mech->submit(); $mech->success or die "post failed: ", $mech->response->status_line; my $lo_response = $mech->get($lo_url); die "Error at $lo_url\n ", $lo_response->status_line, "\n Aborting" un +less $lo_response->is_success; print "\n\nDone.\n\n";

Replies are listed 'Best First'.
Re: screen scraping MECHANIZE
by Limbic~Region (Chancellor) on Feb 05, 2005 at 14:46 UTC
    You still haven't corrected the typo I made and corrected back in the other thread. I waited for a reply - why didn't you say something wasn't working back then? Have you tried the corrected code?

    You might also want to look at an example of working code using WWW::Mechanize. It is nearly impossible for us to tell you what you are doing wrong because we don't have access to your router to test with.

    Cheers - L~R

      L~R Thanks. I did add the a to autocheck. It gives the same results. It's not updating the check boxes. I will plow through the tutorial. Thank you.
        The only way that I can see for this to work is for you to run:
        #!/usr/bin/perl use strict; use warnings; use WWW::Mechanize; my $url= ''; my $mech = WWW::Mechanize->new( autocheck => 1 ); $mech->credentials( '', 'FVS318', 'admin' => 'secret' ); $mech->get( $url ); print $mech->content();
        And paste the result here in CODE and READMORE tags. We can then create a mock up locally to do testing.

        Cheers - L~R

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://428322]
Approved by Corion
[Corion]: Cosmic37: Ah, see perlfaq4, about How do I compute the intersection of two arrays
[Cosmic37]: I am out of practice; I use Perl for scientific programming for number crunching
[Corion]: Cosmic37: Basically, you read one file into a hash, keyed by your key, and then match the lines from the second file to that hash
[Cosmic37]: note that the two files only have datetimes which may match whereas other data per line is different format in file1 and file2 - is that really intersection?
[jedikaiti]: Hi Monks
[Corion]: Cosmic37: Well, if you want to use only parts of a line for the key, see split or whatever other mechanism to extract the key from the line
[Corion]: Hi jedikaiti!
[Cosmic37]: is there a webpage for full CB for this chat rather than side panel chat?
[Cosmic37]: thank you for advice
[Cosmic37]: peach greets jedi

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2017-06-29 16:18 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (672 votes). Check out past polls.