Módulos de Web no Perl
Neste artigo apresento alguns métodos para trabalhar com "tags" e "reg" em Perl de maneira simples e prática usando alguns módulos.
Parte 3: Usando TokeParser
Outro módulo bacana de trabalhar é o HTML::TokeParser. Com ele você pode retirar apenas o que quiser sem o uso de regex ou POG. Veja o exemplo:
Executamos o comando abaixo:
perl prog.pl index.html
Abaixo o conteúdo do arquivo index.html:
Veja a saída do programa:
The first major item
Another major header
Ou seja, ele retirou o que estava entre as tags "h1". Bem simples de usar.
Fico por aqui mesmo com o artigo porque tem muitos outros módulos.
Informações sobre outros módulos, vide CPAN.
use HTML::TokeParser;
my $file = shift;
my $p = HTML::TokeParser->new($file);
while ($p->get_tag('h1')) {
&nbso;print $p->get_text(), " ";
}
my $file = shift;
my $p = HTML::TokeParser->new($file);
while ($p->get_tag('h1')) {
&nbso;print $p->get_text(), " ";
}
Executamos o comando abaixo:
perl prog.pl index.html
Abaixo o conteúdo do arquivo index.html:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head><title>Test HTML Page</title>
</head>
<body>
<h1>The first major item</h1>
<h2>Section 1.1</h2>
<p>Some text<p>
<h2>Section 1.2</h2>
<h3>Section 1.2.1</h3>
<p>blah</p>
<h3>Section 1.2.2</h3>
<p>blah</p>
<h1>Another major header</h1>
<h2>Section 2.1</h2>
<h3>Section 2.1.1</h3>
<h3>Section 2.1.2</h3>
<h2>Section 2.2</h2>
</body>
</html>
<html>
<head><title>Test HTML Page</title>
</head>
<body>
<h1>The first major item</h1>
<h2>Section 1.1</h2>
<p>Some text<p>
<h2>Section 1.2</h2>
<h3>Section 1.2.1</h3>
<p>blah</p>
<h3>Section 1.2.2</h3>
<p>blah</p>
<h1>Another major header</h1>
<h2>Section 2.1</h2>
<h3>Section 2.1.1</h3>
<h3>Section 2.1.2</h3>
<h2>Section 2.2</h2>
</body>
</html>
Veja a saída do programa:
The first major item
Another major header
Ou seja, ele retirou o que estava entre as tags "h1". Bem simples de usar.
Fico por aqui mesmo com o artigo porque tem muitos outros módulos.
Informações sobre outros módulos, vide CPAN.
Tony posso te fazer umas perguntas,
o OpenBSD já está usando o driver nvidia ??????
E desktop 3d, algum dia vai ter ????????????
vlw ....