Retrieving web pages

D

Dackle

Newbie question: I'm trying to retrieve general HTML web pages but
running into a few problems, which in part are probably due to the
fact that I've never used Perl modules before. I downloaded
libwww-perl and copied LWP::Simple into the Perl lib directory, but
I'm still having trouble grabbing web pages. I tried something like
this:


use LWP::Simple;
$url="www.torontostar.com";
$content= get($url);

But I keep getting back a type 2 error saying File "internet" does
not exist. I'm using the ActiveState port of Perl on Windows XP
through the Crimson Editor. Any advice? Is there any other way to
retrieve web pages using existing Perl modules?
 
H

Henry Law

Newbie question: I'm trying to retrieve general HTML web pages but
running into a few problems, which in part are probably due to the
fact that I've never used Perl modules before. I downloaded
libwww-perl and copied LWP::Simple into the Perl lib directory, but
I'm still having trouble grabbing web pages. I tried something like
this:

use strict;
use warnings; # Always - no help in this group otherwise!!
use LWP::Simple;
$url="www.torontostar.com";
$content= get($url);

But I keep getting back a type 2 error saying File "internet" does
not exist. I'm using the ActiveState port of Perl on Windows XP
through the Crimson Editor. Any advice? Is there any other way to
retrieve web pages using existing Perl modules?

I don't know what is going wrong on your system (file called
"internet" doesn't sound right, somehow). But your problem is that
you've left out the "http:". This works on my system (Activestate
like yours); try it.

# ------------START-------------
use strict;
use warnings;

use LWP::Simple;
my $url="http://www.torontostar.com";
my $content= get($url);

print substr($content,0,50),"\n";
# --------------END-------------

Output is:
F:\$WIP>problem.pl
<HTML>
<HEAD>
<script language="Javascript" src="h

F:\$WIP>
 
D

Dackle

OK, I'll give it a try. I think I used http:// in the URL and it didn't
work, but I'll try use strict; and use warnings;.
 
H

Henry Law

OK, I'll give it a try. I think I used http:// in the URL and it didn't
work, but I'll try use strict; and use warnings;.

It's not a matter of "trying" ... putting them in makes it easier to
find some kinds of problem and since nobody writes perfect code first
time you should always use them.

Sorry to sound like a school teacher here but I'm trying to help ...
Saying that something "doesn't work" doesn't help people to help you.
Much better to say what you expected it to do and what it actually
did. Anyway, unless there's a bug in perl itself then the code you
write always "works", in the sense that it does what it does. The
problem comes when what it does is not what you thought it would do.

I meant to advise you earlier: it's much better to copy and paste
error messages, rather than giving a general description of them as
you have done above. The exact text is sometimes important.

Lastly, please don't top post; it's against the agreed guidelines for
this group. In addition many people hate it with a passion and most
of them are the ones you need to help you.
 
S

Sherm Pendley

Dackle said:
fact that I've never used Perl modules before. I downloaded
libwww-perl and copied LWP::Simple into the Perl lib directory

That's the first problem. Read and follow the instructions in 'perldoc
perlmodinstall' - don't just copy files around.
I'm still having trouble grabbing web pages. I tried something like
this:

Post the code you tried, not "something like" it. Copy and paste it,
don't try to re-type it.

Have you read the posting guidelines that appear here frequently?

sherm--
 
T

Tintin

Dackle said:
Newbie question: I'm trying to retrieve general HTML web pages but
running into a few problems, which in part are probably due to the
fact that I've never used Perl modules before. I downloaded
libwww-perl and copied LWP::Simple into the Perl lib directory.

You can't just randomly copy parts of Perl modules and hope they will work.

ActiveState Perl uses PPM to manage Perl modules. Either type 'ppm' at the
command line, or follow:

Start->Programs->ActiveState Perl->Perl Package Manager

Anyway, you don't need to install libwww as it comes standard with
ActiveState Perl.
 
D

Dackle

Thanks, I've got it running now. The error was in fact caused by
the filename in the text editor and not Perl itself. Sorry for the
confusion and the sloppiness.
 
V

VBSome

If all you are trying to do is navigate some web pages and look at the
results then I would suggest you use WWW::Mechanize or if on a Win32
platform Win32::IE::Mechanize (which is the same module as the first one but
uses IE as a browser). These 2 modules are much easier to use then LWP.
 

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

No members online now.

Forum statistics

Threads
474,444
Messages
2,571,709
Members
48,796
Latest member
Greg L.
Top