Solved

open URL in perl

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Perl - Mawk 2 95
Writing a parser for java language 4 78
Perl - Passing cookies received with CGI::Cookie through to and from LWP::UserAgent->Post 5 93
Perl tar error 8 64
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

785 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