Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: How to get WWW::Mechaize::Firefox to get text?

by zerocred (Beadle)
on Apr 22, 2014 at 15:58 UTC ( [id://1083194]=note: print w/replies, xml ) Need Help??


in reply to Re: How to get WWW::Mechaize::Firefox to get text?
in thread How to get WWW::Mechaize::Firefox to get text?

Thanks Corion!

So here it is:

#!/usr/bin/perl -w use strict; use Data::Dumper; use WWW::Mechanize::Firefox; my $mech = WWW::Mechanize::Firefox->new( launch => '/usr/bin/firefox', tab=>'current', frames => 1, ); $mech->get('http://www.example.com'); # wait for JS to render the login button my $retries = 10; #by xpath while ($retries-- and ! $mech->is_visible( {xpath => '//*[@id="login"] +' } )) { sleep 1; }; die "Timeout while waiting for site to appear" if 0 > $retries; print "waitiing retries = $retries\n"; #type the uid & pw $mech->field( username => 'username'); #by name $mech->field( password => 'password'); #by name #sync cos hangs here otherwise $mech->click( {id=>'login', synchronize => 0}); #by id here my $string; my @elements = $mech->xpath('xpath/selector/to/secret/question'); #by +xpath here for(my $x=0;$x<=$#elements;$x++){ $string = $elements[$x]->{innerHTML}; #get the string print "secret question is elements[$x] = $string\n"; #in case ther +e are multiple matches } #ok you need some regex here to decide which question is being asked a +nd reply with corresponding answer $mech->field( SecQuestion => 'secret answer'); #by name here $mech->click( {id=>"confirm", synchronize => 0});

There seemed to be issues about the match of the secret question array having multiple responses.

You asked for many elements but seem to only want a single item. Did you forget to pass the 'single' option with a true value? Pass 'all => 1' to suppress this message and receive the count of item +s.
I think it was trouble shooting lines of code I had added that put me in the wrong iframe... or something.

Thanks for the hints, they really helped!

z

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1083194]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-04-26 09:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found