EXTRAER URLS DE LA ENTRADA ESTANDARD - .: .: Saiyine :. :.

Extraer URLs de la entrada estandard

Por Saiyine Enviar correo el 2004-12-16 00:00:00 - Secciones:  PERL  - Enlace permanente: 386

Un script que he escrito en un momento para sacar las urls que han ido saliendo en la web. Además, si hay un texto en title lo usa como explicación del enlace.

#!/usr/bin/perl
while ()
{
$linea=$_;
while ($linea=~/(<a href="(http[^"]+?)" target="_blank" title="([^"]*?)">(.*?)<\/a>)/i )
{
$url=$2;
$titulo=$3;
$texto=$4;
if ( !$titulo )
{
$titulo=$texto;
}
print "<li><a href=\"$url\" target=\"_blank\" title=\"$titulo\">$titulo.\n";
$linea=~s/(<a href="(http[^"]+?)" target="_blank" title="([^"]*?)">(.*?)<\/a>)//i;
}
}

¿Como se podria hacer que de igual si el target está o no, o que no importe el orden?

Otras entradas de la web que podrian interesarte:

Gravatar 3290
Banderita Keith Amling (2005-09-23 13:25:14)

Correctly handling arbitrary HTML in a regex is a little difficult. The most robust way to handle this (at least with a regex) to first check against /<a ([^>]*)>/ and then check the return from that against /title="([^"]*)"/ and /href="([^"]*)"/ separately to parse title and URL. Extracting links from HTML is a hard problem and the correct (although slow) answer is to use HTML::Parser.

I apologize for English. I can pretend to read Spanish, but not to write it.

Gravatar 3291
Banderita Saiyine (2005-09-24 00:51:14)

Hi!

Yeah, the truth is that this is just a quick'n'dirty hack I can't remember right now why I wrote. Maybe for a module for this web in its pre .com era? I don't know.

You're absolutely correct, the best way is to reuse the code someone, better programmer than I, wrote and put in the HTML::Parser, but it's simply that I don't like to use external libraries for this kind of things.

I apologize for my English too!

o o o o 


Tu nombre (Nick):

Tu correo (Email):
  Necesario para tu gravatar!

Tu página (URL):

Escribe aqui tu comentario:

       :noworry: :roll: :huh: :push: :OO 8) 8O :( :) :? :D :P :o :x :| ;) ^^ xD



Vista previa activada.

Vista previa (6/6/6, 6:66)


Fondos de pantalla

. . .

Recomendamos


. . .

Descargas

  • ApagaPC
    apagapc241.exe  (4339)
  • LimpiaDocus
    LimpiaDocus001.exe  (3627)
  • RCM
    rcm001.zip  (3062)
  • Popmail
    popmail-0.4-psmn.tar.gz  (3132)
  • Manual de Delphi en PDF
    delphi_pdf.zip  (3764)
  • Evangelio del Perl
    Evangelio_del_perl.pdf  (3786)
  • Excel Simpsons
    Excel Simpsons  (3789)
  • . . .

    Proyectos Online

  • Saiyine Store
  • Kunowalls!!!
  • Fondos de pantalla
  • Picaday: imagenes sexys o chocantes.
  • Scarlett: fotos de Scarlett Johansson
  • WhatsmyIP: obtener tu IP pública
  • Uma Thurman: galeria de Uma Thurman
  • FunPics: imagenes graciosas
  • . . .

    Blogs

  • Por lo que más querais, no entreis a estos: Tapanez, Yhandros, Onez.

  • Otros en español: El Mundo Today, La libreta de Van Gaal, Chavalina, Kirai, Mundo Geek, Microsiervos.

  • Mis lecturas en guiri: Michael Yon, Coding Horror, YCombinator news, MySQL Performance, Slashdot.

    . . .
  • Utilidades

  •  Coral  (1583), cacheando webs
  •  Spam.la  (1899), correo de usar y tirar
  •  Mailinator  (1802), correo de usar y tirar
  •  Bug me not  (1580), absurdos registros di NO
  •  Trashmail  (1629), correo de usar y tirar

    . . .

  • Saipuntos

    Jomer: 2
    Yhandros: 1
    Cheimy: 1

    . . .

    Página web ©2001-2011 Saiyine descargada en s, con 5908318 visitas en total, hoy (de un total de 0 previstas).

    . . .