Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
perl html解析库/工具_Perl_Beautifulsoup - Fatal编程技术网

perl html解析库/工具

perl html解析库/工具,perl,beautifulsoup,Perl,Beautifulsoup,是否有一些强大的perl工具/libs,比如从BeautifulSoup到python 谢谢对于大多数问题来说都是一个不错的解决方案。我从未使用过BeautifulSoup,但是快速浏览一下它的文档,您可能会想要它。它甚至可以很好地处理已损坏的文档,并允许遍历已解析的树或查询项-在中查看look\u down方法 如果您喜欢/了解XPath,请参阅daxim的建议。如果您想通过CSS选择器选择项目,请查看或。在寻找功能时,您可以使用XML::LibXML解析HTML。这样做的好处是,您可以使用P

是否有一些强大的perl工具/libs,比如从BeautifulSoup到python


谢谢

对于大多数问题来说都是一个不错的解决方案。

我从未使用过BeautifulSoup,但是快速浏览一下它的文档,您可能会想要它。它甚至可以很好地处理已损坏的文档,并允许遍历已解析的树或查询项-在中查看
look\u down
方法


如果您喜欢/了解XPath,请参阅daxim的建议。如果您想通过CSS选择器选择项目,请查看或。

在寻找功能时,您可以使用XML::LibXML解析HTML。这样做的好处是,您可以使用Perl提供的最快、最好的XML工具链(excecpt MSXML,仅限MS)来处理您的文档,包括XPath和XSLT(如果使用XML::LibXML以外的其他解析器,则需要重新解析)

use strict;
use warnings;
use XML::LibXML;
# In 1.70, the recover and suppress_warnings options won't shup up the
# warnings. Hence, a workaround is needed to keep the messages away from
# the screen.
sub shutup_stderr {
    my( $subref, $bufref ) = @_;
    open my $fhbuf, '>', $bufref;
    local *STDERR = $fhbuf;
    $subref->(); # execute code that needs to be shut up
    return;
}
# ==== main ============================================================
my $url = shift || 'http://www.google.de';
my $parser = XML::LibXML->new( recover => 2 ); # suppress_warnings => 1
# Note that "recover" and "suppress_warnings" might not work - see above.
# https://rt.cpan.org/Public/Bug/Display.html?id=58024
my $dom; # receive document
shutup_stderr
    sub { $dom = $parser->load_html( location => $url ) }, # code
    \my $errmsg; # buffer
# Now process document as XML.
my @nodes = $dom->getElementsByLocalName( 'title' );
printf "Document title: %s\n", $_->textContent for @nodes;
printf "Lenght of error messages: %u\n", length $errmsg;
print '-' x 72, "\n";
print $dom->toString( 1 );