Solved

Trying to parse html file

Posted on 2003-10-27
4
186 Views
Last Modified: 2010-03-05
I'm trying to run a book example and I get the following error.

E:\>perl parser.pl
Can't locate HTML/Tagset.pm in @INC (@INC contains: E:/ind/perl/lib E:/ind/perl/
site/lib .) at E:/ind/perl/site/lib/HTML/LinkExtor.pm line 31.
BEGIN failed--compilation aborted at E:/ind/perl/site/lib/HTML/LinkExtor.pm line
 31.
Compilation failed in require at parser.pl line 5.
BEGIN failed--compilation aborted at parser.pl line 5.

sourcecode

#!e:/ind/perl/bin/perl -w

use strict;
use LWP::UserAgent;
use HTML::LinkExtor;
use URI::URL;

my $url = URI::URL->new('http://www.perl.com/');
my $base_url;

# Create new UserAgent object (browser)
my $ua = LWP::UserAgent->new();

# Give our agent a name
$ua->agent("Mozilla/4.7");

# Create HTTP GET request
my $request = HTTP::Request->new(GET => $url);

# Execute HTTP request
my $response = $ua->request($request);

# Check success
if ($response->is_success && $response->content_type eq 'text/html') {
    # Request was successful and is html
    $base_url = $response->base();
    print "Base URL: $base_url\n";
    my $link_extor = HTML::LinkExtor->new(\&extract_links);
    $link_extor->parse($response->content);
} else {
    # Request failed - print response code and message
    print "Error getting document: ", $response->status_line, "\n";
}

sub extract_links {
    my ($tag, %attr) = @_;

    if ($tag eq 'a' or $tag eq 'img') {
        foreach my $key (keys %attr) {
            if ($key eq 'href' or $key eq 'src') {
                my $link_url = URI->new($attr{$key});
                my $full_url = $link_url->abs($base_url);
                print "LINK: $full_url\n";
            }
        }
    }
}
0
Comment
Question by:mistadontplay
4 Comments
 
LVL 5

Accepted Solution

by:
fantasy1001 earned 63 total points
ID: 9631885
Not sure of the problem. Please check whether module tagset.pm is in the directory E:/ind/perl/site/lib/HTML/. If not, please download from
http://search.cpan.org/~sburke/HTML-Tagset-3.03/Tagset.pm

After copy, if the problem still arise, add a line use HTML::Tagset; to the top of your source code

Thanks & Cheers
0
 
LVL 8

Assisted Solution

by:davorg
davorg earned 62 total points
ID: 9633418
HTML::LinkExtor uses HTML::Tagset. It seems that you've installed HTML::LinkExtor, but not HTML::Tagset.
0
 
LVL 20

Expert Comment

by:jmcg
ID: 10038301
Nothing has happened on this question in over 2 months. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to
split points between fantasy1001 and davorg.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SIMPLE Perl Regex 1 153
problem with using the glob function 1 63
Perl Frameworks 1 78
Call Shell Script from Perl Script 6 76
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now