Perl HTML::Element如何向下查找以提取匹配标记后的下一个标记

Perl HTML::Element如何向下查找以提取匹配标记后的下一个标记,perl,html-treebuilder,Perl,Html Treebuilder,我正在使用HTML::TreeBuilder处理HTML文件。在这些文件中,我可以有定义列表,其中有定义为“数据库名称”的术语“数据库”。模拟html如下所示: #!/usr/bin/perl -w use strict; use warnings; use HTML::TreeBuilder 5 -weak; use feature qw( say ); my $exampleContent = '<dl> <dt data-auto="citation_fi

我正在使用HTML::TreeBuilder处理HTML文件。在这些文件中,我可以有定义列表,其中有定义为“数据库名称”的术语“数据库”。模拟html如下所示:

#!/usr/bin/perl -w

use strict;
use warnings;
use HTML::TreeBuilder 5 -weak;
use feature qw( say );

my $exampleContent = '<dl>  
    <dt data-auto="citation_field_label"> 
    <span class="medium-bold">Language:</span> 
    </dt> 
    <dd data-auto="citation_field_value"> 
    <span class="medium-normal">English</span>
    </dd>
    <dt data-auto="citation_field_label"> 
    <span class="medium-bold">Database:</span> 
    </dt> 
    <dd data-auto="citation_field_value"> 
    <span class="medium-normal">Data Archive</span>
    </dd> 
    </dl>';

my $root = HTML::TreeBuilder->new_from_content($exampleContent);

my $dlist = $root->look_down("_tag" => "dl");

foreach my $e ($dlist->look_down("_tag" => 'dt', "data-auto" => "citation_field_label")) {
   if ($e->as_text =~ m/Datab.*/) {
    say $e->as_text; # I have found "Database:" 'dt' field
    # now I need to go to the next field 'dd' and return the value of that
  } 
}
#/usr/bin/perl-w
严格使用;
使用警告;
使用HTML::TreeBuilder 5-弱;
使用特征qw(例如);
我的$exampleContent
语言:
英语
数据库:
数据档案
';
my$root=HTML::TreeBuilder->new\u from\u content($exampleContent);
my$dlist=$root->look_down(“_tag”=>“dl”);
对于每个我的$e($dlist->look_down(“\u tag”=>“dt”,“data auto”=>“引文字段\u标签”)){
如果($e->as_text=~m/Datab.*/){
说$e->as_text;#我已经找到了“数据库:”“dt”字段
#现在我需要转到下一个字段'dd'并返回该字段的值
} 
}
我需要确定文件来自哪个数据库并返回值


我希望能够像
say$dlist->right()->那样以文本的形式说
当我在
中标识了“Database:”时,但我不知道如何识别。您的想法将不胜感激。

您就快到了。使用

$e->right->as_text;
给我“数据存档”。

太好了,谢谢。:-)有时候想到TreeBuilder和HTML,我会头疼,但这是值得的。所以
right
给出了相同级别的下一个元素,对吗?