Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

How to load and view and HTML page from perl (was: Open Page)

by Anonymous Monk
on May 09, 2002 at 02:00 UTC ( [id://165231]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am interested in loading and viewing an html page within a perl script. For instance, I would like to be able to ask perl to go fetch http://web.mit.edu/bin/cgicso?query=username%3Ddgarcia and then tell me what class year the student is in by examining the page that is fetched.

I am not sure what command or library to use to do such a fetch.

Thanks,
David Garcia

Edit kudra, 2002-05-09 Changed title, added HTML format

  • Comment on How to load and view and HTML page from perl (was: Open Page)

Replies are listed 'Best First'.
Re: Open Page
by tachyon (Chancellor) on May 09, 2002 at 04:34 UTC

    You gotta love perl don't you. A dozen lines (with error handling!) If you want to get a login and learn some perl then I'm sure the monks will be more than willing to help you to say read in a list of usernames from file using open() and the input operator, get their year data, build a data structure, sort() the results by year and then print() the results to your screen or a file which is presumably what you have in mind. You can find out how to do all this using Tutorials and Super Search right here.

    #!/usr/bin/perl -w use strict; use LWP::Simple; my $username = 'dgarcia'; $username =~ s/(\W)/ uc sprintf "%%%02x", ord $1 /eg; # url encode non + alpanumerics my $url = "http://web.mit.edu/bin/cgicso?query=username%3D$usernam +e"; my $page = get($url); if ($page =~ /No matches to your query/) { warn "User '$username' could not be found!\n"; } else { my ($year) = $page =~ m/year:\s*(\d+)/; warn "Could not find year for user '$username'\n" unless defined $ +year; print "User $username is in year $year\n"; }

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: Open Page
by IndyZ (Friar) on May 09, 2002 at 03:10 UTC
    You are probably looking for the modules in Bundle::LWP. Run a search on this site for that and LWP::Simple for plenty of great examples of their use.

    --
    IndyZ

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://165231]
Approved by ehdonhon
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (7)
As of 2024-04-19 20:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found