Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others imbibing at the Monastery: (15)
    As of 2015-07-02 09:51 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (33 votes), past polls