CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Autofilling a webform of other domain

 



companion
Novice

Feb 11, 2008, 8:20 PM

Post #1 of 22 (2728 views)
Autofilling a webform of other domain Can't Post

Hi all,

Is it possible to write a perl program that do autofilling of the login webform(username, password) of other domain (say hotmail.com). Assume domain name, username, password are passed as arguments to the perl program.

Thanks
companion


KevinR
Veteran


Feb 11, 2008, 10:39 PM

Post #2 of 22 (2727 views)
Re: [companion] Autofilling a webform of other domain [In reply to] Can't Post

If there is no javascript involved, WWW::Mechanize is one possibility.
-------------------------------------------------


companion
Novice

Feb 11, 2008, 10:57 PM

Post #3 of 22 (2723 views)
Re: [KevinR] Autofilling a webform of other domain [In reply to] Can't Post


In Reply To
If there is no javascript involved, WWW::Mechanize is one possibility.


Hi KevinR

Can u explain me with a simple perl code? By running the program is web browser will be launched?

Thanks
companion


KevinR
Veteran


Feb 11, 2008, 11:18 PM

Post #4 of 22 (2721 views)
Re: [companion] Autofilling a webform of other domain [In reply to] Can't Post

search on CPAN for WWW::Mechanize

http://search.cpan.org/

WWW::Mechanize has a number of examples and a FAQ. I rarely use it myself so I have almost no practical experience with it.
-------------------------------------------------


companion
Novice

Feb 12, 2008, 12:48 AM

Post #5 of 22 (2719 views)
Re: [KevinR] Autofilling a webform of other domain [In reply to] Can't Post

Hi KevinR

I tried with a simple program. The program goes like this


Code
 
#!/usr/bin/perl

use strict;
use WWW::Mechanize;

my $login = "login_name";
my $password = "password";

my $url = "http://www.gmail.com";
my $mech = WWW::Mechanize->new();
$mech->get($url);
$mech->submit_form(
form_number => 1,
fields => { User => $login },
fields => { Password => $password },
);
die unless ($mech->success);


After executing at terminal I am getting the following error

Can't locate WWW/Mechanize.pm in @INC (@INC contains: /System/Library/Perl/5.8.6/darwin-thread-multi-2level /System/Library/Perl/5.8.6 /Library/Perl/5.8.6/darwin-thread-multi-2level /Library/Perl/5.8.6 /Library/Perl /Network/Library/Perl/5.8.6/darwin-thread-multi-2level /Network/Library/Perl/5.8.6 /Network/Library/Perl /System/Library/Perl/Extras/5.8.6/darwin-thread-multi-2level /System/Library/Perl/Extras/5.8.6 /Library/Perl/5.8.1 .) at login.pl line 4.
BEGIN failed--compilation aborted at login.pl line 4.

Please help me. I am on mac os x.

Thanks
companion


KevinR
Veteran


Feb 12, 2008, 1:44 AM

Post #6 of 22 (2717 views)
Re: [companion] Autofilling a webform of other domain [In reply to] Can't Post

You need to install the module.

http://www.cpan.org/misc/cpan-faq.html#How_install_Perl_modules
-------------------------------------------------


companion
Novice

Feb 12, 2008, 3:51 AM

Post #7 of 22 (2714 views)
Re: [KevinR] Autofilling a webform of other domain [In reply to] Can't Post

Hi KevinR

Thanks for ur information. What about the launch of the browser. I am having firefox. Is it launches when I run the script?


Thanks
companion


KevinR
Veteran


Feb 12, 2008, 1:06 PM

Post #8 of 22 (2704 views)
Re: [companion] Autofilling a webform of other domain [In reply to] Can't Post

Sorry, not sure what you are asking. You could run the script as a CGI (like this forum is a CGI script) in a browser or as a command line script without the browser.
-------------------------------------------------


companion
Novice

Feb 12, 2008, 8:11 PM

Post #9 of 22 (2700 views)
Re: [KevinR] Autofilling a webform of other domain [In reply to] Can't Post


In Reply To
Sorry, not sure what you are asking. You could run the script as a CGI (like this forum is a CGI script) in a browser or as a command line script without the browser.


Hi KevinR

Thanks for ur reply. I will get back to you if I face some other problems.

Thanks
companion


companion
Novice

Feb 12, 2008, 11:23 PM

Post #10 of 22 (2695 views)
Re: [companion] Autofilling a webform of other domain [In reply to] Can't Post

Hi KevinR

When I tried to install the www::mechanize module I got the following error

User_Name-MacBook:~ User_Name$ perl -MCPAN -e shell
Terminal does not support AddHistory.

cpan shell -- CPAN exploration and modules installation (v1.7601)
ReadLine support available (try 'install Bundle::CPAN')

cpan> install WWW::Mechanize

CPAN: Storable loaded ok
Going to read /Users/User_Name/.cpan/Metadata
Warning: Found only 0 objects in /Users/User_Name/.cpan/Metadata
LWP not available
CPAN: Net::FTP loaded ok
Fetching with Net::FTP:
ftp://ftp.perl.org/pub/CPAN/authors/01mailrc.txt.gz
Issuing "/usr/bin/ftp -n"User_Name
Trying 128.118.2.96...
ftp: connect to address 128.118.2.96: Operation timed out
Trying 140.127.177.15...
ftp: connect: Operation timed out
Not connected.
Local directory now /Volumes/Development/Users/User_Name/.cpan/sources/authors
Not connected.
Not connected.
Not connected.
Not connected.
Not connected.
Not connected.
Bad luck... Still failed!
Can't access URL ftp://ftp.perl.org/pub/CPAN/authors/01mailrc.txt.gz.

Please check, if the URLs I found in your configuration file () are valid.
The urllist can be edited. E.g. with 'o conf urllist push ftp://myurl/'

Could not fetch authors/01mailrc.txt.gz
LWP not available
Fetching with Net::FTP:
ftp://ftp.perl.org/pub/CPAN/modules/02packages.details.txt.gz
Issuing "/usr/bin/ftp -n"
Trying 128.118.2.96...
ftp: connect to address 128.118.2.96: Operation timed out
Trying 140.127.177.15...
ftp: connect: Operation timed out
Not connected.
Local directory now /Volumes/Development/Users/User_Name/.cpan/sources/modules
Not connected.
Not connected.
Not connected.
Not connected.
Not connected.
Not connected.
Bad luck... Still failed!
Can't access URL ftp://ftp.perl.org/pub/CPAN/modules/02packages.details.txt.gz.

Please check, if the URLs I found in your configuration file () are valid.
The urllist can be edited. E.g. with 'o conf urllist push ftp://myurl/'

Could not fetch modules/02packages.details.txt.gz
LWP not available
Fetching with Net::FTP:
ftp://ftp.perl.org/pub/CPAN/modules/03modlist.data.gz
Issuing "/usr/bin/ftp -n"
Trying 128.118.2.96...
ftp: connect to address 128.118.2.96: Operation timed out
Trying 140.127.177.15...
ftp: connect: Operation timed out
Not connected.
Local directory now /Volumes/Development/Users/User_Name/.cpan/sources/modules
Not connected.
Not connected.
Not connected.
Not connected.
Not connected.
Not connected.
Bad luck... Still failed!
Can't access URL ftp://ftp.perl.org/pub/CPAN/modules/03modlist.data.gz.

Please check, if the URLs I found in your configuration file () are valid.
The urllist can be edited. E.g. with 'o conf urllist push ftp://myurl/'

Could not fetch modules/03modlist.data.gz
Going to write /Users/User_Name/.cpan/Metadata
Warning: Cannot install WWW::Mechanize, don't know what it is.
Try the command

i /WWW::Mechanize/

to find objects with matching identifiers.

cpan>



So how to rectify this?

Thanks
companion


KevinR
Veteran


Feb 12, 2008, 11:40 PM

Post #11 of 22 (2693 views)
Re: [companion] Autofilling a webform of other domain [In reply to] Can't Post

Well, I can't determine why your computer can't connect, but my guess would be a firewall is blocking perl from accessing the internet. disable the firewall or try and add perl to the list of programs that can access the internet. Either that or the ftp site was just down for some reason.

But only you can determine why the connection is timing out when you run it on your computer, so if a firewall is not the issue you need to try and figure out what is.
-------------------------------------------------


companion
Novice

Feb 13, 2008, 12:38 AM

Post #12 of 22 (2690 views)
Re: [KevinR] Autofilling a webform of other domain [In reply to] Can't Post

Thanks KevinR for ur reply.


companion


companion
Novice

Feb 13, 2008, 8:14 PM

Post #13 of 22 (2682 views)
Re: [companion] Autofilling a webform of other domain [In reply to] Can't Post

Hi KevinR

I found other way of installing the module. I have already downloaded the file WWW-Mechanize-1.34.tar.gz and unzipped it. The commands that we need to execute are as follows.

perl Makefile.PL
make
make test
make install

But during execution of the 3rd command the system dumping a huge amount of data on the screen. I don't know what it is. I will put here some snippet of it here

User_Name-MacBook:~/Desktop/WWW-Mechanize-1.34 User_Name$make test

PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/00-load.t t/add_header.t t/aliases.t t/area_link.t t/autocheck.t t/clone.t t/die.t t/field.t t/find_frame.t t/find_image.t t/find_inputs.t t/find_link-warnings.t t/find_link.t t/find_link_id.t t/form-parsing.t t/frames.t t/image-new.t t/image-parse.t t/link-base.t t/link-relative.t t/link.t t/new.t t/pod-coverage.t t/pod.t t/regex-error.t t/save_content.t t/select.t t/taint.t t/tick.t t/upload.t t/warn.t t/warnings.t t/local/back.t t/local/click.t t/local/click_button.t t/local/failure.t t/local/follow.t t/local/form.t t/local/get.t t/local/overload.t t/local/page_stack.t t/local/referer.t t/local/reload.t t/local/submit.t t/live/computers4sure.t t/live/wikipedia.t t/mech-dump/mech-dump.t
t/00-load................# Failed test (t/00-load.t at line 7)
t/00-load................NOK 1# Tried to use 'WWW::Mechanize'.
# Error: Can't locate HTTP/Request.pm in @INC (@INC contains: /Volumes/Development/Users/User_Name/Desktop/WWW-Mechanize-1.34/blib/lib /Volumes/Development/Users/User_Name/Desktop/WWW-Mechanize-1.34/b
-----------------------------------------------
-----------------------------------------------
Failed 33/47 test scripts, 29.79% okay. 371/410 subtests failed, 9.51% okay.
make: *** [test_dynamic] Error 2

So how to rectify this one.

Thanks
companion


companion
Novice

Feb 13, 2008, 11:26 PM

Post #14 of 22 (2678 views)
Re: [companion] Autofilling a webform of other domain [In reply to] Can't Post

Hi KevinR

I fixed the promblem of execution of the scripts. I prefixed each command with sudo and all went well. But now I found problem with script itself.
I copied a script from http://search.cpan.org/~petdance/WWW-Mechanize-1.34/lib/WWW/Mechanize/Examples.pod


Code
 
#!/usr/bin/perl

# turn on perl's safety features
use strict;
use warnings;

# work out the name of the module we're looking for
my $module_name = $ARGV[0]
or die "Must specify module name on command line";

# create a new browser
use WWW::Mechanize;
my $browser = WWW::Mechanize->new();

# tell it to get the main page
$browser->get("http://search.cpan.org/");

# okay, fill in the box with the name of the
# module we want to look up
$browser->form_number(1);
$browser->field("query", $module_name);
$browser->click();

# click on the link that matches the module name
$browser->follow_link( text_regex => $module_name );

my $url = $browser->uri;

# launch a browser...
system('Firefox', $url);

exit(0);


But I am getting the following error

User_Name-MacBook:~/Desktop USer_Name$ perl temp.pl www::mechanize
There is no form numbered 1 at temp.pl line 21
Can't call method "value" on an undefined value at /Library/Perl/5.8.6/WWW/Mechanize.pm line 1247.

Even I looked at the source the webpage and found the name of the form as "f". Then I changed the code $browser->form_number(1); to
$browser->form_name('f'); again its not working. What might be the problem?

Thanks
companion


KevinR
Veteran


Feb 14, 2008, 10:53 AM

Post #15 of 22 (2669 views)
Re: [companion] Autofilling a webform of other domain [In reply to] Can't Post

The number is the order in which forms are found on the page, if there is only one form it is 1. Your code sort of worked for me after I changed this line:


Code
$browser->follow_link( text_regex => $module_name

);

to:


Code
$browser->follow_link( text_regex => qr{$module_name} );


because the argument is supposed to be a regexp not just text.

Then the code returned:

http://search.cpan.org/~asnmtap/ASNMTAP-3.000016001/lib/ASNMTAP/Asnmtap/Applications/CGI.pod

(I entered 'CGI' as the argument)


I have little practical experience with WWW::Mechanize so I am really not going to be able to help much. When running your code make sure there is no firewall blocking your perl script from accessing the internet.
-------------------------------------------------


companion
Novice

Feb 17, 2008, 8:21 PM

Post #16 of 22 (2656 views)
Re: [KevinR] Autofilling a webform of other domain [In reply to] Can't Post

Hi KevinR,

Sorry for the late back to you. I tried the same program with changes what you have specified but still I am getting the same error. How about the launch of the bowser? Did you find browser launching?


Thanks
companion


KevinR
Veteran


Feb 18, 2008, 1:06 PM

Post #17 of 22 (2648 views)
Re: [companion] Autofilling a webform of other domain [In reply to] Can't Post

You're asking the wrong person, I have almost no experience with that module. And it's too complex a module for me to want to try and learn it well enough to answer your questions. I suggest you hop over to perlmonks.com or devshed.com or possibly tek-tips.com and see if those more active perl forums have someone that can help you out.
-------------------------------------------------


companion
Novice

Feb 18, 2008, 8:06 PM

Post #18 of 22 (2645 views)
Re: [KevinR] Autofilling a webform of other domain [In reply to] Can't Post

Thanks KevinR I will go through those websites


Thanks
companion


eWish
User

Feb 19, 2008, 11:48 AM

Post #19 of 22 (2636 views)
Re: [companion] Autofilling a webform of other domain [In reply to] Can't Post

One thing to keep in mind is that your field names must be an exact match.

The code in post #5 does not match that of Google's login page. Therefore, it will not work.

Also, you might check out WWW::Mechanize::FormFiller might be easier for what you are wanting to do.

--Kevin


KevinR
Veteran


Feb 19, 2008, 1:24 PM

Post #20 of 22 (2633 views)
Re: [eWish] Autofilling a webform of other domain [In reply to] Can't Post

http://www.thescripts.com/forum/thread772274.html Wink
-------------------------------------------------


eWish
User

Feb 19, 2008, 3:22 PM

Post #21 of 22 (2628 views)
Re: [KevinR] Autofilling a webform of other domain [In reply to] Can't Post

There seems to be a plethora of them lately. Cool


KevinR
Veteran


Feb 19, 2008, 3:41 PM

Post #22 of 22 (2626 views)
Re: [eWish] Autofilling a webform of other domain [In reply to] Can't Post

yes a veritable plethora Smile
-------------------------------------------------

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives