Solved

open URL in perl

Posted on 2006-07-19
8
2,071 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

919 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now