Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Powerful Monks, please forgive me because I've committed a sin. After few days inside this community, I've had the arrogance to elevate myself to the level of gods and create a Monk from /dev/null...

It actually taught me to use WWW::Mechanize, which I find quite useful! Here's the code for the virtual monk:

#!/usr/bin/perl use strict; use warnings; use WWW::Mechanize; use HTTP::Response; my ($user, $passwd) = ("anotherTime", "no_abuse_please"); my $homepage = 'http://www.perlmonks.org/'; print STDERR "getting homepage [$homepage]\n"; my $mech = WWW::Mechanize->new( agent => 'Virtual Monk 0.1' ); $mech->get($homepage)->is_success() || die "unable to get $homepage, s +topped"; print STDERR "logging in\n"; $mech->submit_form( form_name => 'login', fields => { user => $user, passwd => $passwd }, button => 'login' )->is_success() || die "unable to log in $homepage, stopped"; # Ensure we've logged in successfully my $logout = $mech->find_link( text => "log $user out" ); die "did not log in, stopped" unless $logout; my $votes = 0; for (my $maxcount = 0; $maxcount < 100; ++$maxcount) { print STDERR "going in my home node\n"; $mech->follow_link( text => $user )->is_success() || die "could not get into my home node, stopped"; print STDERR "assessing if I've spare votes\n"; last unless $mech->response()->content() =~ /You have <b>([0-9]+)< +\/b> votes? left today\./; last unless $1; # Find a page where I can vote. Index indicates the index of the v +oting form my $index = 0; for (my $maxcount2 = 0; $maxcount2 < 100 && ! $index; ++$maxcount2 +) { print STDERR "getting a random page\n"; $mech->follow_link( text => 'Random Node' )->is_success() || die "could not get a random node, stopped"; print STDERR "verifying I can vote anywhere in it\n"; my $count = 0; foreach my $form ($mech->forms()) { ++$count; # Form numbers start from 1 if (defined($form->find_input('sexisgreat', 'submit'))) { $index = $count; last; } } } if ($index) { # A voting form is available print STDERR "casting a vote\n"; $mech->form_number($index); $mech->set_visible( [ radio => "1" ] ); $mech->click('sexisgreat'); ++$votes; } } print STDERR "$votes vote" . ($votes != 1 ? "s" : "") . " cast\n"; # Log out print STDERR "logging out\n"; $mech->get($logout->url()) || die "unable to log out, stopped";
The virtual monk in the configuration is a registered account... forgive me for this as well. Being an acolyte, I think it should be expected some - ehr - inclination to break rules..

The virtual monk isn't running in a cron job, tough. No, it's not running with my account as well :) I'm only wondering how much time it would require him to become saint - I'll evaluate this and post here if some god doesn't kick me out!

Flavio.

-- Don't fool yourself.

In reply to Confessions of a virtual monk by polettix

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2022-05-22 08:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (80 votes). Check out past polls.

    Notices?