#!/usr/bin/perl use strict; use warnings; use HTML::Parser; my $parser = HTML::Parser->new( start_h => [ \&start, "self,tag,attr" ], start_document_h => [ \&init, "self" ] ); $parser->parse_file('ert.html'); foreach my $link ( @{ $parser->{_links} } ) { print $link, "\n"; } sub init { my ($self) = @_; $self->{_links} = []; } sub start { my ( $self, $tag, $attribs ) = @_; if ( $tag eq 'p' && exists $attribs->{class} && $attribs->{class} eq 'g' ) { $self->handler( start => \&get_href, "self,tag,attr" ); } } sub get_href { my ( $self, $tag, $attribs ) = @_; if ( $tag eq 'a' && exists $attribs->{href} && exists $attribs->{onmousedown} ) { push @{ $self->{_links} }, $attribs->{href}; } $self->handler( start => \&start, "self,tag,attr" ); }