Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Answer: How can my script retrieve the contents of an existing webpage?

( #6203=categorized answer: print w/ replies, xml ) Need Help??

Q&A > HTTP and FTP clients > How can my script retrieve the contents of an existing webpage? contributed by vroom

Another option if you have lynx on your system would be
$webpage=`lynx -source http://blah.com`; #gets html source of documen +t $webpage=`lynx -dump http://blah.com`; #returns output as formatted + text

Comment on Answer: How can my script retrieve the contents of an existing webpage?
Download Code
Here's the correct syntax
by furtive (Initiate) on Sep 02, 2001 at 20:35 UTC
    Not quite. you're calling the shell and need to do it properly, here is the correct syntax:
    $webpage=system("lynx -source http://blah.com");
    Otherwise you will literaly get lynx -source http://blah.com as a scaler.

      Sorry, but even that's untrue. vroom likely meant to enclose his code in backticks (`), not single quotes. That solution would've worked. But using system will only give you the return value from the system call instead of the output (although you'll likely get the output on your screen, it won't be stored in $webpage, which is the whole point here).

      What you want is qx, or backticks. They will return the output of the system call:

      $webpage = qx[ lynx -source http://blah.com ]; # Or... $webpage = `lynx -source http://blah.com`;

      Whichever fits your style and the situation best.

      His Royal Cheeziness

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2014-09-15 05:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (145 votes), past polls