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

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, 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.