read from an external web page

C

canes_venatici

Hi -

I'm new to CGI and perl. I am trying to write a script that will read
in the source of a webpage on an external server, look for a specific
string, and then output based on the presence of that string. I've
tried using a pipe to get this done but haven't got it to work. I
can't figure out how to read in the source from an external web page.


Example: lets say i want to read in the source code from
http://www.google.com and look for a string in that code.


I've tried


open (HTML, "http://www.google.com") || print "Can't open page";
$temp_var = <HTML>;
close(HTML);


My output is ALWAYS "Can't open page". I've tried opening to
"http:\/\/www.google.com" with the same results... Am i formatting it
wrong? Is there another way to do this? Is this even possible?


Again this is only an example... i will be doing this on an Internal
and internal server only.. i just used www.google.com as an example.


any help is surely welcome.


Austin
(e-mail address removed)
 
A

A. Sinan Unur

I'm new to CGI and perl.

CGI is not Perl and Perl is not CGI.
I am trying to write a script that will read
in the source of a webpage on an external server, look for a specific
string, and then output based on the presence of that string. I've
tried using a pipe to get this done but haven't got it to work. I
can't figure out how to read in the source from an external web page.


Example: lets say i want to read in the source code from
http://www.google.com and look for a string in that code.


I've tried


open (HTML, "http://www.google.com") || print "Can't open page";

open is use to open local files.
$temp_var = <HTML>;
close(HTML);

If the call to open fails, it is not wise to go on your merry way
attempt to read from the filehandle.
My output is ALWAYS "Can't open page". I've tried opening to
"http:\/\/www.google.com" with the same results...

Why do you think this would make a difference?

You can use LWP::Simple to do this.

However, given your question, I am also going to strongly urge you to
actually get a good book, and learn the basics of Perl.

Sinan

--
A. Sinan Unur <[email protected]>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
 
J

John W. Krahn

canes_venatici said:
Hi -

I'm new to CGI and perl. I am trying to write a script that will read
in the source of a webpage on an external server, look for a specific
string, and then output based on the presence of that string. I've
tried using a pipe to get this done but haven't got it to work. I
can't figure out how to read in the source from an external web page.


Example: lets say i want to read in the source code from
http://www.google.com and look for a string in that code.


I've tried


open (HTML, "http://www.google.com") || print "Can't open page";
$temp_var = <HTML>;
close(HTML);

open() only works on files that are available locally.

perldoc lwpcook
perldoc LWP



John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top