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

I need a perl script that logs on my site, gets the html code and then parse the code to find something I need.
I write a script that works just for some site (e.g. it can log on www.mail.yahoo.com) but when I use it to log on my site the submit doesn't works.

My code is:

#d:\Perl\bin\perl.exe use Win32::GUI; use Win32::OLE; use Win32::GUI::AxWindow; $Window = new Win32::GUI::Window ( -title => "Win32::GUI::AxWindow and Win32::OLE", -pos => [100, 100], -size => [900, 500], -name => "Window", ) or die "new Window"; $Button1 = new Win32::GUI::Button ( -parent => $Window, -name => "Button1", -pos => [0, 25], -size => [200, 50], -text => "Login", ); # more buttons here .. $Control = new Win32::GUI::AxWindow ( -parent => $Window, -name => "Control", -pos => [0, 100], -size => [700, 450], -control => "Shell.Explorer.2", ) or die "new Control"; $OLEControl = $Control->GetOLE(); Win32::OLE->WithEvents($OLEControl,\&Event,"DWebBrowserEvents2"); $url = "http://mysite.com"; $OLEControl->Navigate2($url); Win32::OLE->MessageLoop; $Window->Show(); Win32::GUI::Dialog(); our $doc; # Button Event sub Button1_Click { $OLEControl->{Document}->{login}->{cont}->{value}= "cont"; $OLEControl->{Document}->{login}->{parola}->{value} = "*****"; $OLEControl->{Document}->{login}->{submit}; Win32::OLE->MessageLoop; $doc = $OLEControl->{Document}->{body}->{innerHTML}; }

Could someone help me?

Replies are listed 'Best First'.
Re: A tool that logs and then parses the returned HTML.
by CountZero (Bishop) on Dec 23, 2003 at 11:35 UTC
    Rather than using Win32::* modules, have a look at the Perl Library for WWW LWP, esp. the UserAgent, which can go out and get the HTML code for you in a much more portable and standard way.

    Update: To log in with a login-id and password, you use the "credentials" (search in the docs of the UserAgent for "credentials"). There is a simple overloaded UserAgent which prompts you for the log-in and password: see LWP::AuthenAgent.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

          Thanks for the suggestion, but my script should log in without promting (the script will be sheduled to run in background once a day).

        In that case just use the basic UserAgent and provide the credentials in the script.

        CountZero

        "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Re: A tool that logs and then parses the returned HTML.
by Art_XIV (Hermit) on Dec 23, 2003 at 14:40 UTC

    WWW::Mechanize may be right up your alley. It wraps LWP and in many cases can take care of logins and passwords for you.

    Hanlon's Razor - "Never attribute to malice that which can be adequately explained by stupidity"