Solved

open URL in perl

Posted on 2006-07-19
8
2,105 Views
Last Modified: 2010-07-27
Hi experts,

I’m currently testing hundreds of URL. All URL require the same username and password to open.
My question is how can I open an URL in Perl?
Once I successfully access the URL, how can I let Perl fill in the username and password?
Any way, all I want to do is to write a little Perl script to test these URLs instead of me going through hundreds of them manually.

Thanks a lot  
0
Comment
Question by:jamewang
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
8 Comments
 
LVL 17

Accepted Solution

by:
mjcoyne earned 500 total points
ID: 17137686
Sounds like a job for WWW::Mechanize (see http://search.cpan.org/dist/WWW-Mechanize/lib/WWW/Mechanize.pm).

From the synopsis:

"WWW::Mechanize, or Mech for short, helps you automate interaction with a website. It supports performing a sequence of page fetches including following links and submitting forms. Each fetched page is parsed and its links and forms are extracted. A link or a form can be selected, form fields can be filled and the next page can be fetched. Mech also stores a history of the URLs you've visited, which can be queried and revisited."

Example:

    use WWW::Mechanize;
    my $mech = WWW::Mechanize->new();

    $mech->get( $url );

    $mech->follow_link( n => 3 );
    $mech->follow_link( text_regex => qr/download this/i );
    $mech->follow_link( url => 'http://host.com/index.html' );

    $mech->submit_form(
        form_number => 3,
        fields      => {
            username    => 'mungo',
            password    => 'lost-and-alone',
        }
    );

    $mech->submit_form(
        form_name => 'search',
        fields    => { query  => 'pot of gold', },
        button    => 'Search Now'
    );
0
 

Author Comment

by:jamewang
ID: 17150814
Thanks mjcoyne, but how do i get around the password prompt. I don't think that count as the first form in the page.
0
 
LVL 17

Expert Comment

by:mjcoyne
ID: 17150886
Are the username and password fields part of an HTML page?
0
 

Author Comment

by:jamewang
ID: 17150900
I don't think so, It prompts me to enter the username and password
0
 
LVL 17

Expert Comment

by:mjcoyne
ID: 17151306
You'll need to tell me what is generating the password prompt -- is it in a pop-up window?  Is it being triggered by HTML, JavaScript, .htaccess files, or what?

See also http://search.cpan.org/~prashant/Win32-IEAutomation-0.5/lib/Win32/IEAutomation.pm.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question