automate website login using perl

Discussion in 'Perl Misc' started by tester, Sep 23, 2005.

  1. tester

    tester Guest

    Hi All,

    I am trying to automate login to a website using the following code. but
    it is not working ... any ideas?
    ----------------------
    use HTTP::Request;
    use LWP::UserAgent;

    $http_cmd = "http://testertesting:80/login.html";

    my %tags = ();
    $tags{'action'} = 'calling page/servlet';
    $tags{'id'} = 'User';
    $tags{'username'} = 'user';
    $tags{'password'} = 'passwd';

    # Create a user agent object
    use LWP::UserAgent;
    $ua = LWP::UserAgent->new;
    $ua->agent("MyApp/0.1 ");

    # Create a request
    my $req = HTTP::Request->new(POST => $http_cmd);
    $req->content_type('application/x-www-form-urlencoded');
    $req->content( %tags );

    # Pass request to the user agent and get a response back
    my $resp = $ua->request($req);

    print $resp->content;
    ----------------------

    ~tester
     
    tester, Sep 23, 2005
    #1
    1. Advertising

  2. tester

    Brian Wakem Guest

    tester wrote:

    > $http_cmd = "http://testertesting:80/login.html";


    > my $req = HTTP::Request->new(POST => $http_cmd);



    I doubt you want to post to login.html


    > print $resp->content;



    And what did it print, login.html?



    --
    Brian Wakem
    Email: http://homepage.ntlworld.com/b.wakem/myemail.png
     
    Brian Wakem, Sep 23, 2005
    #2
    1. Advertising

  3. tester

    tester Guest

    I am getting "500 read timeout"

    Brian Wakem wrote:
    > tester wrote:
    >
    >
    >>$http_cmd = "http://testertesting:80/login.html";

    >
    >
    >>my $req = HTTP::Request->new(POST => $http_cmd);

    >
    >
    >
    > I doubt you want to post to login.html
    >
    >
    >
    >>print $resp->content;

    >
    >
    >
    > And what did it print, login.html?
    >
    >
    >
     
    tester, Sep 23, 2005
    #3
  4. tester

    Brian Wakem Guest

    tester wrote:

    > I am getting "500 read timeout"



    Don't top post.

    Then your script is fine. Either you are POSTing to the wrong address or
    the target server is misconfigured.



    --
    Brian Wakem
    Email: http://homepage.ntlworld.com/b.wakem/myemail.png
     
    Brian Wakem, Sep 23, 2005
    #4
  5. tester

    tester Guest

    Hi Brian,
    I don't understand "Don't top post"? :-(

    I wonder whether POST takes the form page url or the target page url
    (login credentials verification page)!
    If I give the form page url then I am getting page content as output
    If I give the target page url then I am getting "500 read timeout"

    Thankyou,
    tester

    Brian Wakem wrote:
    > tester wrote:
    >
    >
    >>I am getting "500 read timeout"

    >
    >
    >
    > Don't top post.
    >
    > Then your script is fine. Either you are POSTing to the wrong address or
    > the target server is misconfigured.
    >
    >
    >
     
    tester, Sep 23, 2005
    #5
  6. tester

    Paul Lalli Guest

    tester wrote:
    > Hi Brian,
    > I don't understand "Don't top post"? :-(


    Have you considered asking Google what it means, before posting again?
    You obviously have figured out you're doing *something* wrong, but
    rather than attempt to figure out what it was, you just went ahead and
    posted again, following the same style you have been. How can that not
    be considered rude?

    When I type "top post" into the Google homepage, I get this as the
    first result:
    http://catb.org/~esr/jargon/html/T/top-post.html&e=10342

    Paul Lalli
     
    Paul Lalli, Sep 23, 2005
    #6
  7. tester

    Brian Wakem Guest

    tester wrote:

    > Hi Brian,
    > I don't understand "Don't top post"? :-(
    >
    > I wonder whether POST takes the form page url or the target page url
    > (login credentials verification page)!
    > If I give the form page url then I am getting page content as output
    > If I give the target page url then I am getting "500 read timeout"



    It's the target url, so my all of my previous answer still applies.


    --
    Brian Wakem
    Email: http://homepage.ntlworld.com/b.wakem/myemail.png
     
    Brian Wakem, Sep 23, 2005
    #7
  8. On Fri, 23 Sep 2005 18:04:15 +0530, tester wrote:

    > Hi All,
    >
    > I am trying to automate login to a website using the following code. but
    > it is not working ... any ideas?


    Once you do have it working, you will almost certainly need a cookie jar
    (instructions for the use of which you will find in the LWP docs). This is
    because web sites typically use a cookie for persistent logins.

    Rich
     
    Richard Gration, Sep 23, 2005
    #8
  9. tester

    pdc Guest

    Paul Lalli,
    I guess you either do not work in customer service, or don't care about
    others' feelings when they ask for help. Accusing someone of being rude
    simply because they don't adhere to the same grammatical rules as you seems
    a bit harsh.
    As for the advice to google everything one does not understand; Let's all
    stop using newsgroups and stop asking anyone else for help -- all the
    information is available through google surely?

    As for top posting, When people regularly quote entire passages in their
    posts, I actually prefer to see the latest text at the top of the list.

    <quoted text snipped out of courtesy>
     
    pdc, Sep 23, 2005
    #9
  10. "pdc" <> wrote in
    news:hrZYe.11967$:

    > Paul Lalli,
    > I guess you either do not work in customer service,


    There are no customers here.

    There is a difference between being a paying customer, and asking for
    others to donate their time.

    ....

    > As for top posting, When people regularly quote entire passages in
    > their posts, I actually prefer to see the latest text at the top of
    > the list.


    The recommendation is to quote an appropriate amount of context so your
    post stands on its own.

    The justification for this recommendation can be found in the
    guidelines.

    I think, it this case, the OP got confused between 'post' as in posting
    to a newsgroup and HTTP POST when reading Brian Wakem's response. He
    could have used Google to understand the diffence:

    http://www.google.com/search?q=top posting

    Sinan

    PS: *PLONK*

    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
     
    A. Sinan Unur, Sep 24, 2005
    #10
  11. tester

    Paul Lalli Guest

    pdc wrote:
    > Paul Lalli,
    > I guess you either do not work in customer service,


    I am not working here. Are you paying me? I'm donating my time and
    knowledge. What I ask in return is not a paycheck, but that those
    requesting assistance follow a few simple requests and make an attempt
    to solve their problems on their own.

    > or don't care about others' feelings when they ask for help.


    100% correct. I am not a shrink. I am not here to make anyone feel
    good about him/herself. If you have a question about Perl, and I am
    able to assist, I will be happy to do so. Your emotional and
    psychological state is wholly irrelevant to me.

    > Accusing someone of being rude
    > simply because they don't adhere to the same grammatical rules as you seems
    > a bit harsh.


    I have no idea what you're talking about. No where in this thread (or
    any other I can remember off hand), did I ever mention anyone's grammar
    or lack there of.

    > As for the advice to google everything one does not understand; Let's all
    > stop using newsgroups and stop asking anyone else for help -- all the
    > information is available through google surely?


    Stop asking the newsgroup? Absolutely not. Attempting to find the
    information on one's own before wasting the time of hundreds of people
    around the world? Damn right.

    > As for top posting, When people regularly quote entire passages in their
    > posts,


    People should *not* be quoting entire passages in their post. They
    should be trimming it down to a relevant amount of material. Have you
    read the Posting Guidelines?

    > I actually prefer to see the latest text at the top of the list.


    Well congratulations, but the vast majority of people who frequent this
    group - the ones actually offering our time, assistance, and knowledge,
    rather than requesting it of others - prefer a different style. When
    people are asking for free assistance, I don't think it's out of line
    to request that they follow that style.

    > <quoted text snipped out of courtesy>


    Single most ironic statement I've seen in this group in at least 2
    months. It is courteous to not follow the standard traditions and
    customs of the people who've been in this group several magnitudes of
    time longer than you? You need a better dictionary.

    Paul Lalli
     
    Paul Lalli, Sep 24, 2005
    #11
  12. pdc <> wrote:
    > Paul Lalli,
    > I guess you either do not work in customer service,



    That is not relevant, since Usenet is not a help-desk.


    > or don't care about
    > others' feelings when they ask for help. Accusing someone of being rude
    > simply because they don't adhere to the same grammatical rules as you seems
    > a bit harsh.



    You seem to have missed the point of Paul's post, since it was not
    about grammatical rules. It was Brian's post that pointed out the
    grammatical rules preferred here.

    Paul's post was about asking hundreds (thousands?) of people around
    the world a question that is easily answered without taking up
    those volunteers time. (and thereby drawing them away from helping
    others who have a not-easily-found answer.)

    He then went on to provide the additional "customer service" of
    teaching how this question could have been answered more quickly
    and efficiently.

    Learning the approach he suggested will help answer not only _this_
    question, but many future questions as well.

    He taught the OP how to fish rather than simply giving him a fish.


    > As for the advice to google everything one does not understand; Let's all

    ^^^^^^^^^^
    ^^^^^^^^^^
    > stop using newsgroups and stop asking anyone else for help -- all the

    ^^^
    ^^^
    > information is available through google surely?



    You are being disingenuous there, as we do not object to _all_ questions.

    We do, however, object to answering questions whose answer is
    easily answered in a standard place, such as the docs or a
    Usenet archive.

    We are not a "look it up for me" service, we are a "help me because
    I've looked for the answer, but could not find it" service.


    > As for top posting, When people regularly quote entire passages in their
    > posts, I actually prefer to see the latest text at the top of the list.



    That's nice, but also irrelevant, since a properly quoted followup
    does not meet your "entire" predicate.

    A properly quoted followup would have included only enough of a
    passage to indicate the context for the comment that is to follow.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Sep 24, 2005
    #12
  13. tester

    pdc Guest

    I do apologise if I caused offence. It was an admittedly rash reaction to
    what I read as a disparaging response to a reader's request for assistance.
    I did not fully understand the general attitude of the many respondants to
    this group.
     
    pdc, Sep 25, 2005
    #13
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. [nix]
    Replies:
    1
    Views:
    3,941
    [nix]
    Sep 7, 2003
  2. yurps
    Replies:
    0
    Views:
    381
    yurps
    Jun 10, 2005
  3. yurps

    automate asp.net debug login

    yurps, Jun 14, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    501
    yurps
    Jun 14, 2005
  4. [nix]

    automate file upload using perl

    [nix], Sep 7, 2003, in forum: Perl Misc
    Replies:
    1
    Views:
    105
    Brian McCauley
    Sep 7, 2003
  5. perlperl

    automate command line script using perl

    perlperl, Jun 15, 2006, in forum: Perl Misc
    Replies:
    6
    Views:
    384
    perlperl
    Jun 16, 2006
Loading...

Share This Page