| Welcome to WebmasterWorld Guest from 18.104.22.168 |
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
|Become a Pro Member|
|Grab source code from any supplied URL|
There must be an easy way to do this...
Hi, I'm would like to have a form with a field where the user supplies any URL. Clicking submit then grabs the source of the page specified in the URL.
Does anyone know the basic syntax for this? I'm gathering one uses the CGI module...
You don't have to use the CGI module. Have you looked into LWP?
Ah right, thanks Dr. Doc...so something like this?
$query = new CGI;
$webpage = $query->param("web_url");
my $source = get $webpage ;
But now I have another problem, I have the source of the URL stored in the $source. However, I wish to convert each source line into an array @source, to do further manipulations.
Usually, one would open a file and assign each line using <> as below:
open(DAT, $data_file) ¦¦ die("Could not open file!");
But for my case, I don't have a file which I'm opening, just a very long variable $source. So, I want to do something like:
@source = <$source>
But obviously, that is incorrect syntax.
Probably best to use the split function :-
That will give an array with one line of code per entry.
(NB that should work for pages stored in *nix format. For Windows files you might have to use a more complicated regex to deal with the \r carriage returns as well as the \n newlines...)
Why not use a script? Try http,//willmaster.com/master/snooper/
You will need the LWP::Simple mod, and probably already have it installed.
All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved