Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

This is my first post here. Let me know if I format something outside of what you guys prefer. I like that you guys do your best to inform new people how to not frustrate the community. Anyway, I am running Strawberry Perl v5.12.3 on windows (I really only say this because parts of mech perl seem buggy, but I admit it could be my perl), and I need to follow this link.:

<a class="menuItem" href="#" onclick="sListView.check_entire_list(document.MassUpdate, "mass[]",true,4063);" onmouseout="unhiliteItem(this);" onmouseover="hiliteItem(this,"yes");" style="width: 150px">Select All&nbsp;(4063)</a>

The problem with this box, may be that it is hidden and only shows up when you click a javascripted button. Yes, hidden, it is not some ajax appearing nonsense. I figured it would still parse it, but I seriously tried 50 or so regexes. Less ideally(WAY less, but I would put up with it), I could check this box, and add a massive amount of logic to click through pages that are variable. :/

<input id="massall" class="checkbox" type="checkbox" onclick="sListView.check_all(document.MassUpdate, "mass[]", this.checked);" value="" name="massall">

I have tried these kinds of things:

$mech->follow_link( text_regex => /select\sall/i ) if $mech->success() +; $mech->find_link(text_regex=>/select/i);

It always returns saying that there is a use of uninitialized variable $_ in the mech perl code, or it says that I initialized a hash with an odd number of items and so forth. So... I went through the more annoying method (this one will probably add 3 or 4 days to my project, but whatever). Let's check the box:

$mech->tick( 'massall', /\s/ ); $mech->tick( 'massall', / / ); $mech->tick( 'massall', '' ); $mech->tick( 'massall', 0 ); $mech->tick( 'massall', '&nbsp;' );

Perl wont allow use of uninitialized value, null value or it cannot find &nbsp; or \s. It not finding \s is bizarre to me because then I leave a null value it states that the regex is not valid. What do I do?

Replies are listed 'Best First'.
Re: Mech::Perl and following links w/ null value
by Corion (Patriarch) on Apr 18, 2012 at 13:56 UTC

    There is no module named Mech::Perl. If you are talking about WWW::Mechanize as your unshown code seems to imply, please read WWW::Mechanize to find what attributes the parameters for ->follow_link act on. You will find that none act on the onClick attribute and none of them act on <input... elements. Please also review the documentation of ->tick to find out what its arguments are and how they work. Especially, passing the result of a regular expression match makes little sense, and there is no hint in the documentation that passing a regular expression like qr/\s/ would be supported.

    It would help us to help you better if you provided a short, 10-20 line, self-contained working example that reproduces the error. For example something like the following:

    #!perl -w use strict; use WWW::Mechanize; my HTML = <<HTML; <html> <body> <form> <input ... </form> </body> </html> HTML my $mech = WWW::Mechanize->new(); $mech->update_html($html); $mech->tick(...);
Re: Mech::Perl and following links w/ null value
by tobyink (Canon) on Apr 18, 2012 at 13:52 UTC

    What exactly do you mean by "Mech::Perl"? CPAN has no such module. Do you perhaps mean WWW::Mechanize or WWW::Mechanize::Firefox?

    WWW::Mechanize doesn't support Javascript.

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
Re: Mech::Perl and following links w/ null value
by ajinkyagadewar (Novice) on Apr 19, 2012 at 06:32 UTC

    Hi,
    Let me try to help you out for the query you posted.
    First thing is the module you might be using is WWW::Mechanize as pointed right by 'Corion' and 'tobyink'.
    Second point is, follow link will help you only when link is provided in href tag, for example:

    <a name="hotels" id="hotels" href="http://www.name.com/hotels/"></a>

    In your case, onclick is calling a function which points to Jaavascript function.
    Whenever this happens a url is created or the data is posted on site.
    To get right visibility you can use Firebug or LiveHttpHeader (addons for Firefox) to get exact method that site uses to form the query and posting it to a server.

    Check if this preliminary information helps you, otherwise you can reply to my post.

    Regards, Ajinkya