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 24, 2008, 6:01 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.- Hide quoted text -
>
> - Show quoted text -

Thanks everyone for the guidance and useful thought.

The reason I am using Perl, I already developed a program in Perl to
keep track of my time spend on any project. The program is working
fine and basically it is create a pipe delimited text file with the
following information:
Project name|Task name|Date|Amount of time spent

Now my intention is to add a button in that program so that when I
will click that button it will grab the information from the pipe
delimited file and will fill-out the online form.



Posted by J. Gleixner on March 24, 2008, 6:16 pm
Please log in for more thread options
Babul wrote:
[...]
> The reason I am using Perl, I already developed a program in Perl to
> keep track of my time spend on any project. The program is working
> fine and basically it is create a pipe delimited text file with the
> following information:
> Project name|Task name|Date|Amount of time spent
>
> Now my intention is to add a button in that program so that when I
> will click that button it will grab the information from the pipe
> delimited file and will fill-out the online form.

Thanks for sharing your intentions. If you have questions, then post
your code and ask, otherwise no one really needs to know your
intentions.

Posted by Babul on March 24, 2008, 8:47 pm
Please log in for more thread options
wrote:
> Babulwrote:
>
> [...]
>
> > The reason I am using Perl, I already developed a program in Perl to
> > keep track of my time spend on any project. The program is working
> > fine and basically it is create a pipe delimited text file with the
> > following information:
> > Project name|Task name|Date|Amount of time spent
>
> > Now my intention is to add a button in that program so that when I
> > will click that button it will grab the information from the pipe
> > delimited file and will fill-out the online form.
>
> Thanks for sharing your intentions. =A0If you have questions, then post
> your code and ask, otherwise no one really needs to know your
> intentions.

If you think that you are really helpful, please see my code at the
beginning of the discussion. Ben Bullock suggested me to use
greasemonkey, so I explained here why I am using Perl.

Posted by Peter J. Holzer on March 25, 2008, 3:25 am
Please log in for more thread options
> wrote:
>> Babulwrote:
>> > The reason I am using Perl,
[...]
>>
>> Thanks for sharing your intentions.  If you have questions, then post
>> your code and ask, otherwise no one really needs to know your
>> intentions.
>
> If you think that you are really helpful, please see my code at the
> beginning of the discussion. Ben Bullock suggested me to use
> greasemonkey, so I explained here why I am using Perl.

Be more careful in quoting, then. You quoted a lot from Ben's reply but
you didn't quote the part about gresemonkey. Please quote the part you
are replying to (and only that) - otherwise nobody knows what you are
talking about.

The part which you did quote however, did probably identify your
problem. Did you try his advice?

        hp

Posted by Ben Bullock on March 21, 2008, 8:23 pm
Please log in for more thread options
On Fri, 21 Mar 2008 16:57:02 -0700, Babul wrote:

> 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.

You probably need to actually log in via Perl and get the cookies (login
cookie, session cookie) via Perl. Even if your browser is logged in, Perl
isn't able to share the cookies from the browser to access the web page.

Here are some code fragments from a similar automated login which might
help get you started:

# modules I used

use LWP::UserAgent;
use HTML::Form;
use HTTP::Cookies;

# from the generic user agent starter for my login:

sub my_module::start_user_agent
{
my $ua = LWP::UserAgent->new;

$ua->cookie_jar(HTTP::Cookies->new(file => "lwpcookies.txt",
autosave => 1));

return $ua;
}

# from the automated login script:

my $name = $form->find_input ("Name", "text")->value;
my $remember = $form->find_input ("Remember", "checkbox")->value;
my $password;# = $form->find_input ("Password", "text")->value;

$form->value ("Name", "myusername");
$form->value ("Remember", "1");
$form->value ("Password", "mypassword");

$request = $form->click;
$response = $ua->request($request);

# end

I ran the login script as a different script since once I had the cookies
I didn't need to run it again.

Alternatively, if you want to automatically fill in the form from your
browser, don't use Perl, use greasemonkey instead.

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