Perl - Capturar enlaces HREF

 
Vista:

Capturar enlaces HREF

Publicado por José Ramon Martínez (2 intervenciones) el 10/03/2006 10:33:13
Buenos días,

Estoy trabajando en una función que, usando expresiones regulares, capture los enlaces (HREF) de un texto.

Alguien me podría ayudar a simplificarla?
gracias de antemano!!

sub getLinks
{
# crear hash
%hash = ();

for(@_){
while(/(<[^aA][^>]*>|[^<>]+)*<(A|a) (\w+=\"[^\"-]+\" )*((HREF|href)=\"([^\"]+)\")( [\w:;\(\)=\'\"-]*)*>(<[^aA][^>]*>|[^<>]+)*/g){
if ((! exists $hash{$6})&&($6!~/#\w+/)){
$hash{$6}= 1;
}
}<a href="http://XXX">
}
%hash;
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Capturar enlaces HREF

Publicado por Joaquin Ferrero (48 intervenciones) el 12/03/2006 13:48:16
sub getLinks {
my @urls = @_;
my %hash;

foreach my $url ( @urls ) {
while ( $url =~ /href="(.+?)"/gi ) {
$hash{ $1 } = 1 unless $1 =~ /#/;
}
}

return %hash;
}

En el foro de http://perlenespanol.baboonsoftware.com/foro/index.php tendrás mejor soporte que aquí...
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar