Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

opening html files

by joepepsi18 (Novice)
on Jan 14, 2008 at 04:11 UTC ( #662250=perlquestion: print w/replies, xml ) Need Help??

joepepsi18 has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,

this is my first week using perl, so please excuse the stupid question I am about to ask. I hope you all would be able to assist me.

I need to write a script that parses out an html file. Unfortunately, the following only works on local and dir:

for ie:

my $html='http://www.perl.com/pub/a/2000/12/begperl4.html'; open (FH, $html) or die "Cannot open file: $!"; close (FH)

I get the following error: Cannot open file: Invalid argument

Can somebody tell me how I can access the www file so that I may parse it?

thanks so much !!

20080115 Janitored by Corion: Added formatting, code tags, as per Writeup Formatting Tips

Replies are listed 'Best First'.
Re: opening html files
by davidrw (Prior) on Jan 14, 2008 at 04:21 UTC
Re: opening html files
by leighsharpe (Monk) on Jan 14, 2008 at 11:23 UTC
    "http://www.perl.com/pub/a/2000/12/begperl4.html" is not a file. It's a URL. If you are wanting to open a file on your local machine, use the path to the file in $html. Otherwise, if you want to parse the contents of a web site on a remote server, you need to fetch the web page first. LWP::Simple is probably what you want. Alternatively, use wget to fetch the remote site and copy it to a local file, then open the local copy using the method you have outlined above.
Re: opening html files
by fenLisesi (Priest) on Jan 14, 2008 at 11:35 UTC
    joepepsi18,

    Are you planning to write your own HTML parser? If so, tell us about what you need to do with the HTML content and monks will direct you to great, ready to use, well tested HTML parsers on CPAN, too.

    Please take a look at Writeup Formatting Tips for a few quick and easy formatting pointers that may broaden your audience.

    Cheers.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://662250]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2019-11-12 01:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (64 votes). Check out past polls.

    Notices?