LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-24-2007, 12:07 PM   #1
cad
Member
 
Registered: Dec 2006
Distribution: Fedora core 4
Posts: 92

Rep: Reputation: 15
robot script that logs me in and fills forms automatically


Can someone please tell me how to make a script in php or maybe any other lang. that can log me into any website and fill up a form.
Please post any links or whatever solution that anyone might be having. The form is in .aspx format.
Like suppose I have to submit question to LQ so I will login using this php script and fill up the form
Such a script is what I am looking for.

Last edited by cad; 04-24-2007 at 12:14 PM.
 
Old 04-24-2007, 01:19 PM   #2
deadeyes
Member
 
Registered: Aug 2006
Posts: 609

Rep: Reputation: 79
Quote:
Originally Posted by cad
Can someone please tell me how to make a script in php or maybe any other lang. that can log me into any website and fill up a form.
Please post any links or whatever solution that anyone might be having. The form is in .aspx format.
Like suppose I have to submit question to LQ so I will login using this php script and fill up the form
Such a script is what I am looking for.
PHP is a bad language for this (otherwhise also )
I recommend writing it in java.

I made once such a program. You just have to analyze the traffic that is being send and received from the webserver.

After that you can open a socket and generate these packets yourself.
 
Old 04-24-2007, 01:48 PM   #3
slzckboy
Member
 
Registered: May 2005
Location: uk - Reading
Distribution: slackware 14.2 kernel 4.19.43
Posts: 462

Rep: Reputation: 30
I did this in C recently.

The site used the HTTP post method for logging in and used cookies for user/password authentication.

I did what the gent above said.
I used a packet sniffer to see what was going on and then emulated it in my code.
 
Old 04-26-2007, 05:47 AM   #4
cad
Member
 
Registered: Dec 2006
Distribution: Fedora core 4
Posts: 92

Original Poster
Rep: Reputation: 15
Can someone please throw somelight on as to how should I analyze this traffic. And also how to handle the cookies and other session data
Thank you.

Last edited by cad; 04-26-2007 at 06:01 AM.
 
Old 04-26-2007, 08:12 AM   #5
mechdave
Member
 
Registered: Apr 2007
Location: Adelaide, Australia
Distribution: Ubuntu 8.10 and 7.10 server
Posts: 95

Rep: Reputation: 15
RE: robot script that logs me in and fills forms automatically

Perl has routines to do stuff like that in the WWW::Mechanize module
 
Old 04-26-2007, 10:55 PM   #6
cad
Member
 
Registered: Dec 2006
Distribution: Fedora core 4
Posts: 92

Original Poster
Rep: Reputation: 15
I dont know too much about perl.
Can you help me with this WWW::Mechanize module
 
Old 04-26-2007, 10:55 PM   #7
cad
Member
 
Registered: Dec 2006
Distribution: Fedora core 4
Posts: 92

Original Poster
Rep: Reputation: 15
I dont know perl. Can you help me with WWW::Mechanize module
 
Old 04-27-2007, 01:51 AM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
If you don't know Perl, you might struggle a bit ;-), or of course you can learn it....
It's a very good lang... anyway, here's a short example to get you started

Code:
#!/usr/bin/perl -w

use WWW::Mechanize;     # Automate website interactions
use strict;             # Enforce declarations

    my (
        $mech,      # www::mechanize obj
        $error_msg  # generic msg holder
        );

    # Create Mech Obj
    $mech = WWW::Mechanize->new() or
                        exit_with_error("Mech Obj create failed: $@");

    # Get login screen
    $mech->get($cfg::params{'TGT_URL'}) or
                exit_with_error("Get URL $cfg::params{'TGT_URL'} failed: $@");

#DEBUG
#$error_msg = $mech->uri();
#print "URI: $error_msg\n";

    # Fill in Login credentials and submit form to website
    $mech->submit_form( fields =>
                                {
                                    username => $cfg::params{'USER'},
                                    password => $cfg::params{'PASSWD'}
                                }
                        );
    if( !$mech->success() )
    {
        exit_with_error("Submit Login form failed: $@");
    }

#DEBUG
#$error_msg = $mech->uri();
#print "URI: $error_msg\n";

    # Should have received Phone/Msg form, so
    # fill in nums(s), msg and submit form to website
    $mech->submit_form( fields =>
                                {
                                    numbers => $cfg::params{'PHONE_NUM'},
                                    message => $cfg::params{'MESSAGE'}
                                }
                        );
    if( !$mech->success() )
    {
        exit_with_error("Submit Message form failed: $@");
    }

#DEBUG
#$error_msg = $mech->uri();
#print "URI: $error_msg\n";

    # Should have got "Confirmation" screen: click Continue button
    $mech->click_button(number => 1);
    if( !$mech->success() )
    {
        exit_with_error("Submit Confirmation form failed: $@");
    }
HTH
 
Old 04-27-2007, 04:55 AM   #9
mechdave
Member
 
Registered: Apr 2007
Location: Adelaide, Australia
Distribution: Ubuntu 8.10 and 7.10 server
Posts: 95

Rep: Reputation: 15
Post RE: robot script that logs me in and fills forms automatically

I find that http://search.cpan.org is very helpful with function documentation of the modules. The page is here for WWW:Mechanize.
For perl syntax I found this site good (even though it is for windows)
And here is the perl.net.au wiki tutorial
That should give you a reasonably good background to it all
And of course I am glad to help you where I can (I am still learning Perl as well )
 
Old 04-27-2007, 07:23 AM   #10
cad
Member
 
Registered: Dec 2006
Distribution: Fedora core 4
Posts: 92

Original Poster
Rep: Reputation: 15
OK, Thank you very much. I will try this but can someone tell me something about curl which you find in php
Thanks
 
Old 04-27-2007, 09:36 AM   #11
slzckboy
Member
 
Registered: May 2005
Location: uk - Reading
Distribution: slackware 14.2 kernel 4.19.43
Posts: 462

Rep: Reputation: 30
tons of info on their website

http://curl.haxx.se/libcurl/
 
  


Reply

Tags
automatic, form, php



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Automatically logs out madsporkmurderer Ubuntu 1 08-03-2006 09:53 AM
Start X automatically when user logs in? Firewielder Linux - Newbie 4 01-21-2006 10:00 AM
LXer: Linux robot site launches with user-controllable robot LXer Syndicated Linux News 0 01-12-2006 02:46 AM
How to roll logs automatically?? samd Linux - Newbie 6 07-27-2005 12:50 PM
RedHat logs me out automatically glass Linux - Distributions 5 11-03-2002 10:36 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:13 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration