Last active
August 29, 2015 14:05
-
-
Save aereal/2fa75027f407a4aa7701 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Data::Section::Simple qw( get_data_section ); | |
use HTML::TreeBuilder::Select; | |
use HTML::Selector::XPath qw( selector_to_xpath ); | |
use Test::More; | |
my $tree = HTML::TreeBuilder::Select->new(); | |
$tree->parse_content(get_data_section('index.html')); | |
my $section1 = $tree->select('#section-1'); | |
my $section2 = $tree->select('#section-2'); | |
ok $section1; | |
ok $section2; | |
ok $section1->select('.description'); | |
ok ! $section2->select('.description'), '#section-2 以下に .description はない'; | |
subtest 'selector => xpath' => sub { | |
my $selector = '#section-1 .description'; | |
my $xpath = selector_to_xpath($selector); | |
unlike $xpath, qr{\A//}, 'ドキュメント全体から探索しないでほしいんだけど……'; | |
}; | |
done_testing; | |
__DATA__ | |
@@ index.html | |
<div id="section-1"> | |
<p class="description">hello</p> | |
</div> | |
<div id="section-2"> | |
<p>no content</p> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/mirod/HTML--TreeBuilder--XPath/blob/d04414e96152a50ac4356c1457027a44db88c317/lib/HTML/TreeBuilder/XPath.pm#L113
XML::XPathEngine#findnodes に
$context
を渡しているところまでは読んだ。$context
に実際にどんな値が与えられているか$context
をどのように扱っているかはまだ見ていない。