• Publicidad

Leer el título de una página HTML

¿Apenas comienzas con Perl? En este foro podrás encontrar y hacer preguntas básicas de Perl con respuestas aptas a tu nivel.

Leer el título de una página HTML

Notapor Azrack » 2007-09-10 17:32 @772

Disculpen, en el portal encontré este código:
Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
#!/usr/bin/perl -w

use strict;
use CGI::Carp qw(fatalsToBrowser);

use LWP::UserAgent;
use HTTP::Request;


my $ua = LWP::UserAgent->new;
$ua->agent("Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)");

my $url = "http://baboonsoftware.com/";

my $req = HTTP::Request->new(GET => $url);
my $response = $ua->request($req);
my $content = $response->content();

print "Content-type: text/html\n\n";
print $content;
Coloreado en 0.002 segundos, usando GeSHi 1.0.8.4

y me preguntaba si hay alguna forma de leer solo el título de la web u otras cosas.
Azrack
Perlero nuevo
Perlero nuevo
 
Mensajes: 19
Registrado: 2007-04-14 13:42 @613

Publicidad

Notapor kidd » 2007-09-11 09:00 @416

Hola:

Usando LWP::Simple y el módulo HTML::HeadParser puedes hacer algo así:

Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
use LWP::Simple;
use HTML::HeadParser;

my $html = get("http://misitio.com/");

my $p = HTML::HeadParser->new;
$p->parse($html);

my $title = $p->header('Title');
Coloreado en 0.001 segundos, usando GeSHi 1.0.8.4



Saludos
Uriel Lizama Perl programmer fundador de Perl en Español
Perl Programming Language
Avatar de Usuario
kidd
Creador de Perl en Español
Creador de Perl en Español
 
Mensajes: 1166
Registrado: 2003-10-15 16:52 @744
Ubicación: México

Notapor Azrack » 2007-09-11 18:06 @796

Gracias, muy buena tu ayuda.
Azrack
Perlero nuevo
Perlero nuevo
 
Mensajes: 19
Registrado: 2007-04-14 13:42 @613


Volver a Básico

¿Quién está conectado?

Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 15 invitados