Click here to get back home

Perl code to fill-in online form

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Perl code to fill-in online form Babul 03-21-2008
Posted by Babul on March 21, 2008, 7:57 pm
Please log in for more thread options
Hello everyone,

I am trying to write a program in perl (windows) that I will use to
fill out online form.

Here are the steps that I follow to get the online form:
1. I go to the web site first and get a Login form
2. I fill in the Login form and submit that form. Then a page open
with a link "Choose a period". When I click on that link, a small
window pops up with links for different weeks. I click on my desired
week.
3. Now a page display with some project names, dates of my choosen
week and box field to enter time that I spent on that progect.

I tried WWW::Mechanize to get the contents of the web page.

Here are the steps I followed to grab the contents of the web page:
#! /usr/local/bin/perl

use Tk;
use Cwd;
use WWW::Mechanize;
$currentDir = getcwd;

$mech = WWW::Mechanize->new();
$mech->get("web address from the 3rd step above");
$contents = $mech->content();
open WF, ">$currentDir/temp.txt";
print WF "$contents\n";
close WF;

But the contents I get is the source code of the Login page (from step
1 above). My purpose is to get the source code of the web page which
is displayed in step 3.

If any one can help me I would appreciate that.

Note: I also noticed that If I go to View->Source on the Internet
Explorer to view the HTML source code of that web page, it does not
display. But I can view source code using View->Source for any other
web sites.

Regards,

Babul

Posted by Joost Diepenmaat on March 21, 2008, 8:05 pm
Please log in for more thread options

> Hello everyone,

hi!

> I am trying to write a program in perl (windows) that I will use to
> fill out online form.

> 2. I fill in the Login form and submit that form. Then a page open
> with a link "Choose a period". When I click on that link, a small
> window pops up with links for different weeks. I click on my desired
> week.

ok

> I tried WWW::Mechanize to get the contents of the web page.

That's usually the best module to use for this, yes. but it sounds like
the popup is opened via javascript and WWW::Mechanize doesn't support
javascript.

You either have to figure out how to get at the popup's url via
WWW::Mechanize (probably using some hand-written rules), and/or you'll
need to "mechanize" a javascript capable browser. Since you're on
windows, you may want to try Win32::IE::Mechanize.

See
<http://search.cpan.org/~abeltje/Win32-IE-Mechanize-0.009/lib/Win32/IE/Mechanize.pm>

I think this is all mentioned in the docs for WWW::Mechanize too.

[ ...]

> open WF, ">$currentDir/temp.txt";

You don't need to specify the current directory. That's what a current
directory is for.

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/

Posted by Ben Bullock on March 21, 2008, 8:53 pm
Please log in for more thread options
On Sat, 22 Mar 2008 01:05:32 +0100, Joost Diepenmaat wrote:

>
>> Hello everyone,
>
> hi!
>
>> I am trying to write a program in perl (windows) that I will use to
>> fill out online form.
>
>> 2. I fill in the Login form and submit that form. Then a page open with
>> a link "Choose a period". When I click on that link, a small window
>> pops up with links for different weeks. I click on my desired week.
>
> ok
>
>> I tried WWW::Mechanize to get the contents of the web page.
>
> That's usually the best module to use for this, yes. but it sounds like
> the popup is opened via javascript and WWW::Mechanize doesn't support
> javascript.

It's possible but highly unlikely. I think you didn't read where the
poster said that he keeps getting the source code for the login window
when he tries to access the page he wants. The problem is lack of
authentication. If he has the URL for the popup window, window 3, which
he said that he does:

$mech->get("web address from the 3rd step above");

it doesn't matter how window 2 opens window 3. Being opened with
JavaScript has nothing to do with it.

> You either have to figure out how to get at the popup's url via
> WWW::Mechanize (probably using some hand-written rules), and/or you'll
> need to "mechanize" a javascript capable browser. Since you're on
> windows, you may want to try Win32::IE::Mechanize.

No, no, no, this is really bad advice. You didn't read the poster's
question properly.


Posted by Joost Diepenmaat on March 21, 2008, 9:11 pm
Please log in for more thread options

> It's possible but highly unlikely. I think you didn't read where the
> poster said that he keeps getting the source code for the login window
> when he tries to access the page he wants. The problem is lack of
> authentication. If he has the URL for the popup window, window 3, which
> he said that he does:
>
> $mech->get("web address from the 3rd step above");
>
> it doesn't matter how window 2 opens window 3. Being opened with
> JavaScript has nothing to do with it.

Although you state your case a bit confusingly, after re-reading the
original post I agree that my interpretation is probably wrong and yours
is probably correct.

>> You either have to figure out how to get at the popup's url via
>> WWW::Mechanize (probably using some hand-written rules), and/or you'll
>> need to "mechanize" a javascript capable browser. Since you're on
>> windows, you may want to try Win32::IE::Mechanize.
>
> No, no, no, this is really bad advice. You didn't read the poster's
> question properly.

I do wonder why this is bad advice. AFAIK it should "work" either way.

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/

Posted by Ben Bullock on March 22, 2008, 12:40 am
Please log in for more thread options
On Sat, 22 Mar 2008 02:11:02 +0100, Joost Diepenmaat wrote:


>>> You either have to figure out how to get at the popup's url via
>>> WWW::Mechanize (probably using some hand-written rules), and/or you'll
>>> need to "mechanize" a javascript capable browser. Since you're on
>>> windows, you may want to try Win32::IE::Mechanize.
>>
>> No, no, no, this is really bad advice. You didn't read the poster's
>> question properly.
>
> I do wonder why this is bad advice. AFAIK it should "work" either way.

I'm sorry to have written like that. I had this vision of the original
poster spending hours and hours trying to do something which probably
wouldn't have solved his problem.

Similar ThreadsPosted
Webcool24.com : Biggest worldwide Asian free Video multi language web , Travel, Sports, Racing cars , Massages techniques, Games , Fashions, Jokes , Top models , Free online IT learning , 5000 links, 250 free online TV , 50000 music video, nice la August 15, 2007, 8:58 am
online perl... March 25, 2005, 3:14 pm
PERL TK Online tutorial May 30, 2006, 12:16 am
Perl and Online Banking November 25, 2006, 1:54 pm
OO Perl Online Learning February 5, 2007, 12:15 pm
I'm looking for online lecture for perl language? March 25, 2005, 3:12 pm
Good online tutorials on Perl November 1, 2005, 3:31 pm
Online forum source codes in Perl/CGI without SQL? October 23, 2004, 12:00 am
Online Graphing Calculator - Perl Backend June 22, 2006, 11:11 pm
New article online: 'Embedding Perl in database tables' March 18, 2005, 5:31 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap