Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: how to use regular expressions read some string from a htm file

by reneeb (Chaplain)
on Aug 02, 2006 at 05:48 UTC ( [id://565167]=note: print w/replies, xml ) Need Help??


in reply to how to use regular expressions read some string from a htm file

You can use HTML::Parser:
#! /usr/bin/perl use strict; use warnings; use HTML::Parser; my @links; my $string = qq~<a href="url1">linktext1</a> Ein anderer Text <a href="url2">linktext2</a> text~; my $p = HTML::Parser->new(); $p->handler(start => \&start_handler,"tagname,attr,self"); $p->parse($string); foreach my $link(@links){ print "Linktext: ",$link->[1],"\tURL: ",$link->[0],"\n"; } sub start_handler{ return if(shift ne 'a'); my ($class) = shift->{href}; my $self = shift; my $text; $self->handler(text => sub{$text = shift;},"dtext"); $self->handler(end => sub{push(@links,[$class,$text]) if(shift eq 'a +')},"tagname"); }
  • Comment on Re: how to use regular expressions read some string from a htm file
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://565167]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2024-04-18 07:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found