Gossamer Forum
Home : General : Perl Programming :

New to Perl and this forum

Quote Reply
New to Perl and this forum
Hi,

I read a great turtorial which teaches you the basic functions of perl (ie. opening files, conditional statements etc...)

But what I really want to know is how do I open a webpage in a perl program.

My main goal is to create content management for my site.



Thanks,
Quote Reply
Re: [superkman] New to Perl and this forum In reply to
Are you trying to open a URL or are you trying to open up a local html file? If you are trying to open a URL the LWP module should help you.

~Charlie

Last edited by:

Chaz: Jan 4, 2004, 4:34 PM
Quote Reply
Re: [Chaz] New to Perl and this forum In reply to
Thanks,
Quote Reply
Re: [superkman] New to Perl and this forum In reply to
No worries. Was that actually what you were looking for?

~Charlie
Quote Reply
Re: [Chaz] New to Perl and this forum In reply to
I don't know yet, I am planning to read what you gave me.

What I exactly want to do is open a file on the net and save it on my hard drive from the net.

For example use http://www.fileplanet.com/

Could you write a program that opens the index file of www.fileplanet.com and saves the html on your hard drive.

If so please post it here so I could learn from it.

Thanks again Sly
Quote Reply
Re: [superkman] New to Perl and this forum In reply to
LWP is what you want. here is a quick example taken from the POD:

Code:
#!/usr/bin/perl -w
use strict;
require LWP::UserAgent;

my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;

my $response = $ua->get('http://www.fileplanet.com/');

if ($response->is_success) {
print "Content-Type: Text/HTML\n\n";
print $response->content; # or whatever
# The 'or whatever' here would be to save the contents to a file.
# I'll leave that as an exercise for you :)
}
else {
die $response->status_line;
}

I found it here:

http://search.cpan.org/...serAgent.pm#SYNOPSIS

You're just getting what would normally be sent to the browser with this. If the site links to external JS or CSS files, you're not actually downloading those. You'd have to parse through the HTML you do get and download the JS and CSS files if you want em.

~Charlie
Quote Reply
Re: [Chaz] New to Perl and this forum In reply to
Hey chaz could you add me to your icq list

My account is 82976482



Thanks,
Quote Reply
Re: [superkman] New to Perl and this forum In reply to
An even simpler example would be;

Code:
#!/usr/bin/perl

use strict;
use LWP::Simple;

my $url = 'http://www.perl.com';

my $page = get($url);

print "Content-type: text/html \n\n";
print $page;

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] New to Perl and this forum In reply to
Thank you, that worked :D