HTML::...:LibXML(3pm)
π HTML::TreeBuilder::LibXML β the manpage, but make it cute π
okay so bestie, gather round, because we're talking about HTML::TreeBuilder::LibXML (that's the perl manual page, 3pm section, "User Contributed Perl Documentation" energy) and honestly? it's giving speed. π¦
β¨ NAME β¨
HTML::TreeBuilder::LibXML β an HTML::TreeBuilder and XPath compatible interface, but powered by libxml. periodt. π
πΈ SYNOPSIS πΈ
here's the vibe, copy-paste it, no cap:
use HTML::TreeBuilder::LibXML;
my $tree = HTML::TreeBuilder::LibXML->new;
$tree->parse($html);
$tree->eof;
# $tree and $node compatible to HTML::Element
my @nodes = $tree->findvalue($xpath);
for my $node (@nodes) {
print $node->tag;
my %attr = $node->all_external_attr;
}
HTML::TreeBuilder::LibXML->replace_original(); # replace HTML::TreeBuilder::XPath->new
likeβ¦ $tree and $node stay compatible with HTML::Element, so you get to keep your whole little XPath lifestyle π
and then replace_original() just slides in and swaps out HTML::TreeBuilder::XPath->new like it was never there. iconic behaviour.
π DESCRIPTION π
so HTML::TreeBuilder::XPath is a libxml based compatible interface to HTML::TreeBuilder, right? and listen β that's all fine and good, but it could be slow if your document is big. π big documents + slow parsing = the worst.
enter HTML::TreeBuilder::LibXML: it's a drop-in-replacement for HTML::TreeBuilder::XPath. like, literally drop it in. π«Ά
heads up tho: this module doesn't implement all ofHTML::TreeBuilderandHTML::ElementAPIs. but bestie, enough methods are defined that modules likeWeb::Scraperwork. so it's fine. it's fine!! β¨
π₯ BENCHMARK π₯
this is a benchmark result by tools/benchmark.pl β and the numbers are screaming, honestly:
Web::Scraper: 0.26
HTML::TreeBuilder::XPath: 0.09
HTML::TreeBuilder::LibXML: 0.01_01
Rate no_libxml use_libxml
no_libxml 5.45/s -- -94%
use_libxml 94.3/s 1632% --
1632% faster. the way that use_libxml said "let me be the main character" ππ that's not a glow-up, that's a transformation.
π AUTHOR π
- Tokuhiro Matsuno
<tokuhirom@gmail.com> - Tatsuhiko Miyagawa
<miyagawa@cpan.org> - Masahiro Chiba
π THANKS TO π
woremacx++http://d.hatena.ne.jp/woremacx/20080202/1201927162id:dailyflower
shoutout to the legends, fr fr. π«‘
β SEE ALSO β
HTML::TreeBuilderHTML::TreeBuilder::XPath
go read those too, iykyk. πβ¨
π LICENSE π
this library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. slay, and legally so. βοΈβ¨
and that's the whole page, bestie!! πΈ this little gem was served up as perl v5.38.2, dated 2024-08-03, straight from the User Contributed Perl Documentation β so if you ever forget the details, just remember: libxml go brrr, HTML::TreeBuilder::XPath who?, and replace_original() is the plot twist. π¦π ily, go parse something huge and fast. π
π¦ where this page comes from
- debian trixie: libhtml-treebuilder-libxml-perl 0.28-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libhtml-treebuilder-libxml-perl 0.28-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libhtml-treebuilder-libxml-perl 0.28-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms