Solved

open URL in perl

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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 gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

743 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

10 Experts available now in Live!

Get 1:1 Help Now