LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   robot script that logs me in and fills forms automatically (https://www.linuxquestions.org/questions/programming-9/robot-script-that-logs-me-in-and-fills-forms-automatically-548631/)

cad 04-24-2007 12:07 PM

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.

deadeyes 04-24-2007 01:19 PM

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 :p)
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.

slzckboy 04-24-2007 01:48 PM

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.

cad 04-26-2007 05:47 AM

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.

mechdave 04-26-2007 08:12 AM

RE: robot script that logs me in and fills forms automatically
 
Perl has routines to do stuff like that in the WWW::Mechanize module

cad 04-26-2007 10:55 PM

I dont know too much about perl.
Can you help me with this WWW::Mechanize module

cad 04-26-2007 10:55 PM

I dont know perl. Can you help me with WWW::Mechanize module

chrism01 04-27-2007 01:51 AM

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

mechdave 04-27-2007 04:55 AM

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 :study: )

cad 04-27-2007 07:23 AM

OK, Thank you very much. I will try this but can someone tell me something about curl which you find in php
Thanks

slzckboy 04-27-2007 09:36 AM

tons of info on their website

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


All times are GMT -5. The time now is 07:31 AM.