Because of the firewall issues I'm dealing with that I asked about yesterday, I'm trying to use Win32::IE::Mechanize to scrape data from some HTTPS websites.
The issue I'm having is that the execution of my script doesn't seem to wait for IE to load the next page.
My code looks like this:
#!/usr/bin/perl use strict; use Win32::IE::Mechanize; my $ie = Win32::IE::Mechanize->new(visible => 1); my $url = "https://www.securesite.com"; print "Requesting '$url'... "; my $ok = $ie->get($url); $ok ? print "ok\n" : print "failed\n" && exit 1; print "Filling in login form... \n"; $ie->form_number(1); print "Entering username... \n"; $ie->field('username', 'username'); print "Entering password... \n"; $ie->field('password', 'password'); print "ok\n"; print "Submitting login form... "; $ok = $ie->click('_submit'); $ok ? print "ok\n" : print "failed\n" && exit 1; exit; print "Looking for link... \n"; my $link = $ie->find_link(n => 1); if (defined $link) { print "Found link... \n"; print "\tText: ".$link->text."\n"; print "\tURL: ".$link->url."\n"; print "ok\n" } else { print "failed\n"; die; } exit;
After the call to $ie->get(), the script waits until the page is fully loaded before printing 'ok', which is what it's supposed to do. But after $ie->click(), it prints 'ok' quite quickly, not immediately but before the page is loaded, and then the link that is returned from the subsequent method is the first link on the login page, rather than the first link on the page that is arrived at after login.
The page is being submitted -- the right page does load in the IE instance, but after the script has finished.
$ie->click() is actually a call to this method in the Win32::IE::Input class:
=head2 $input->click Calls the C<click()> method on the actual object. This may not work. =cut sub click { ${ $_[0] }->click }
which is not encouraging.
Does anyone have any suggestions as to how to get this to do the right thing?
Thanks!
In reply to Getting Win32::IE::Mechanize to wait for responses by mickey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |