Using Perl to input username and password for website?

Discussion in 'Perl Misc' started by John, Jan 18, 2004.

  1. John

    John Guest

    Hello,

    I was wondering if there was a way to use Perl
    to enter the username and password automatically
    in order to access a particular website. The
    website that I want to access prompts the user
    for the username and password in a pop-up box,
    like so :

    Username :
    Password :

    Then there are two buttons which are OK and Cancel.

    How do I use Perl to input the username and password
    info automatically and "click" the "OK" button?
    Initially, I tried to use the following code that
    I found on this newsgroup (posted by Gregory Toomey),
    but it does not work for my case.

    #!/usr/bin/perl
    use LWP::Simple;
    use strict;

    my $result=get("http://username:password\@www.mysite.com/docs/show.htm");



    I can see why the above does not work since the website I want to
    access asks you to enter the information in a box rather than as shown
    in the code above. I also believe that the website is protected by
    ..htaccess.

    Any help would be appreciated. Thanks!


    John
    John, Jan 18, 2004
    #1
    1. Advertising

  2. In article <>,
    John <> wrote:
    :I was wondering if there was a way to use Perl
    :to enter the username and password automatically
    :in order to access a particular website. The
    :website that I want to access prompts the user
    :for the username and password in a pop-up box,
    :like so :

    :Username :
    :password :

    :Then there are two buttons which are OK and Cancel.

    What is the mechanism that the WWW site is using to pop up the box?
    Is it using Java? Javascript? Is the pop-up box definitely
    different than the normal pop-up credentials box you would get
    for other sites?
    --
    What is "The Ultimate Meme"? Would it, like Monty Python's
    "The World's Funniest Joke", lead to the deaths of everyone who
    encountered it? Ideas *have* lead to the destruction of entire cultures.
    -- A Child's Garden Of Memes
    Walter Roberson, Jan 18, 2004
    #2
    1. Advertising

  3. John wrote:

    > Hello,
    >
    > I was wondering if there was a way to use Perl
    > to enter the username and password automatically
    > in order to access a particular website. The
    > website that I want to access prompts the user
    > for the username and password in a pop-up box,
    > like so :
    >
    > Username :
    > Password :


    Use basic authentication which need no programming.

    http://httpd.apache.org/docs/howto/auth.html

    gtoomey
    Gregory Toomey, Jan 18, 2004
    #3
  4. John <> wrote:

    > website that I want to access prompts the user
    > for the username and password in a pop-up box,



    There are many ways for a browser to display a pop-up box.

    You need to know which way is being used before you can use that way.


    > Any help would be appreciated. Thanks!



    Access the site with the Web Scraping Proxie and see what it tells you:

    Web Scraping Proxy

    http://www.research.att.com/~hpk/wsp/


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Jan 18, 2004
    #4
  5. John

    Chris Guest

    Gregory Toomey wrote:
    > John wrote:
    >
    >
    >>Hello,
    >>
    >>I was wondering if there was a way to use Perl
    >>to enter the username and password automatically
    >>in order to access a particular website. The
    >>website that I want to access prompts the user
    >>for the username and password in a pop-up box,
    >>like so :
    >>
    >>Username :
    >>Password :

    >
    >
    > Use basic authentication which need no programming.
    >
    > http://httpd.apache.org/docs/howto/auth.html
    >


    Dude... This ISN'T what he's asking for...

    CHris
    -----
    Chris Olive
    chris (-at-) technologEase (-dot-) com
    http://www.technologEase.com
    (pronounced "technologies")
    Chris, Jan 18, 2004
    #5
  6. John

    John Guest

    (John) wrote in message news:<>...
    > Hello,
    >
    > I was wondering if there was a way to use Perl
    > to enter the username and password automatically
    > in order to access a particular website. The
    > website that I want to access prompts the user
    > for the username and password in a pop-up box,
    > like so :
    >
    > Username :
    > Password :
    >
    > Then there are two buttons which are OK and Cancel.
    >
    > How do I use Perl to input the username and password
    > info automatically and "click" the "OK" button?
    > Initially, I tried to use the following code that
    > I found on this newsgroup (posted by Gregory Toomey),
    > but it does not work for my case.
    >


    This is a message in reply to Walter Roberson. The website is
    protected by .htaccess using the Apache webserver. So, the pop-up
    box is not Java or Javascript.


    John
    John, Jan 18, 2004
    #6
  7. John

    gnari Guest

    "John" <> wrote in message
    news:...
    > (John) wrote in message

    news:<>...
    >
    > This is a message in reply to Walter Roberson. The website is
    > protected by .htaccess using the Apache webserver. So, the pop-up
    > box is not Java or Javascript.
    >


    have you tried LWP::UserAgent ?
    there is a method called credetials()

    gnari
    gnari, Jan 18, 2004
    #7
  8. John <> wrote:

    > This is a message in reply to Walter Roberson.



    No it isn't.

    It is a reply to your original post.

    If it had been in reply to Walter, then the References: header
    would contain a Message-ID for Walter's message.


    Please learn how to make your newsreader generate a proper followup.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Jan 18, 2004
    #8
  9. John

    Tore Aursand Guest

    On Sun, 18 Jan 2004 16:13:32 +0000, Chris wrote:
    >> Use basic authentication which need no programming.


    > Dude... This ISN'T what he's asking for...


    How do you know? And _what is_ the OP asking for? To me it sounds
    obvious that he/she is asking for help on how to authenticate on a web
    site which is using .htaccess;

    "I also believe that the website is protected by .htaccess."

    Right?

    Anyway: This isn't a Perl thing at all. Doing this with Perl is no
    different from doing it with any other language - it all depends on the
    server (ie. Apache, in this case).


    --
    Tore Aursand <>
    "What we see depends mainly on what we look for." -- Sir John Lubbock
    Tore Aursand, Jan 19, 2004
    #9
  10. On Mon, 19 Jan 2004 08:55:45 +0100, Tore Aursand wrote:

    > How do you know? And _what is_ the OP asking for?


    He's asking about writing a *client*, not about configuring a server. He
    even used LWP in his code.

    > Anyway: This isn't a Perl thing at all.


    Actually, it is. The OP wants to know how to provide authentication
    information using LWP. You could argue that it's an RTFM question - it's
    in the LWP docs - or you could argue that it's better directed to the
    ..modules group.

    sherm--
    Sherm Pendley, Jan 19, 2004
    #10
  11. John

    Tore Aursand Guest

    On Mon, 19 Jan 2004 11:02:48 +0000, Sherm Pendley wrote:
    >> How do you know? And _what is_ the OP asking for?


    > He's asking about writing a *client*, not about configuring a server. He
    > even used LWP in his code.


    That's irrelevant as I see it: The method is excactly the same no matter
    what _client_ you are using.

    Read the Apache documentation for more information about this. You can't
    solve this problem different using a different programming language; The
    solution is excactly the same.

    How you do it with _the language of your choice_ is another story, of
    course.


    --
    Tore Aursand <>
    "Writing is a lot like sex. At first you do it because you like it.
    Then you find yourself doing it for a few close friends and people you
    like. But if you're any good at all, you end up doing it for money."
    -- Unknown
    Tore Aursand, Jan 19, 2004
    #11
  12. On Mon, 19 Jan 2004 12:59:34 +0100, Tore Aursand wrote:

    > That's irrelevant as I see it: The method is excactly the same no matter
    > what _client_ you are using.
    >
    > Read the Apache documentation for more information about this.


    Are you being deliberately difficult???

    The OP is not asking how to configure a server. He's asking how to write,
    in Perl, using LWP, a *client* that provides proper authentication to a
    server that's been password-protected.

    The answer is exactly the same no matter what server you're connecting to
    - Either create an instance of LWP::UserAgent and call its credentials()
    method, or subclass LWP::UserAgent and override the
    get_basic_credentials() method in the subclass.

    sherm--
    Sherm Pendley, Jan 19, 2004
    #12
  13. Well, you don't say what you want to do AFTER you click
    OK, or the browsing/downloading context this is all in.
    But maybe something like this would work? It prints the
    requested document to your screen. You could also redirect
    or save to a file if you wanted.

    use LWP;

    my $url = 'http://some_url/some_document.html';

    my $ua = new LWP::UserAgent;
    my $req = new HTTP::Request (GET => $url);

    $req->authorization_basic ('username', 'password');
    my $request = $ua->request ($req);
    die unless $request->code eq '200';
    my $page = $request->content;
    print $page;


    John wrote:

    > Hello,
    >
    > I was wondering if there was a way to use Perl
    > to enter the username and password automatically
    > in order to access a particular website. The
    > website that I want to access prompts the user
    > for the username and password in a pop-up box,
    > like so :
    >
    > Username :
    > Password :
    >
    > Then there are two buttons which are OK and Cancel.
    >
    > How do I use Perl to input the username and password
    > info automatically and "click" the "OK" button?
    > Initially, I tried to use the following code that
    > I found on this newsgroup (posted by Gregory Toomey),
    > but it does not work for my case.
    >
    > #!/usr/bin/perl
    > use LWP::Simple;
    > use strict;
    >
    > my $result=get("http://username:password\@www.mysite.com/docs/show.htm");
    >
    >
    >
    > I can see why the above does not work since the website I want to
    > access asks you to enter the information in a box rather than as shown
    > in the code above. I also believe that the website is protected by
    > .htaccess.
    >
    > Any help would be appreciated. Thanks!
    >
    >
    > John
    Arvin Portlock, Jan 19, 2004
    #13
  14. John

    John Guest

    Arvin Portlock <> wrote in message news:<buhc4a$2iam$>...


    Thanks everyone for your suggestions. I used the LWP::UserAgent route and
    it worked. Thanks Arvin, your example was very helpful. Thanks to
    gnari as well and everyone who posted in the thread.


    John
    John, Jan 19, 2004
    #14
    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. john brown
    Replies:
    2
    Views:
    918
    Christopher Shatto
    Aug 3, 2004
  2. AAaron123
    Replies:
    2
    Views:
    2,104
    AAaron123
    Jan 16, 2009
  3. Sam S.
    Replies:
    2
    Views:
    190
    Tad McClellan
    Feb 9, 2005
  4. Paul
    Replies:
    1
    Views:
    145
    Paul Lalli
    Aug 15, 2005
  5. Replies:
    1
    Views:
    130
    Michael Austin
    Apr 17, 2009
Loading...

Share This Page