Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.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
使用HTML TreeBuilder XPath findnodes()方法逐个打印匹配结果时需要建议吗_Html_Xml_Perl_Xpath_Html Treebuilder - Fatal编程技术网

使用HTML TreeBuilder XPath findnodes()方法逐个打印匹配结果时需要建议吗

使用HTML TreeBuilder XPath findnodes()方法逐个打印匹配结果时需要建议吗,html,xml,perl,xpath,html-treebuilder,Html,Xml,Perl,Xpath,Html Treebuilder,我正在使用 在Perl中。我已经获得了所需数据的xpath位置。我面临的问题是,xpath$html->FindNodes有几个匹配项,它们由单个结果返回,但我需要逐个打印。需要一些建议。谢谢。您可以使用 for my $node (@$paraelements) { ..... } 一个更完整的例子 use HTML::TreeBuilder::XPath; my $tree= HTML::TreeBuilder::XPath->new; $tree->pars

我正在使用
在Perl中。我已经获得了所需数据的xpath位置。我面临的问题是,xpath$html->FindNodes有几个匹配项,它们由单个结果返回,但我需要逐个打印。需要一些建议。谢谢。

您可以使用

  for my $node (@$paraelements)  { ..... }
一个更完整的例子

  use HTML::TreeBuilder::XPath;
  my $tree= HTML::TreeBuilder::XPath->new;
  $tree->parse_file( "mypage.html");
  my $paraelements= $tree->findnodes( '//p') ;

  for my $node (@$paraelements)  {
      say $node->as_HTML() ;
  }

您可以使用

  for my $node (@$paraelements)  { ..... }
一个更完整的例子

  use HTML::TreeBuilder::XPath;
  my $tree= HTML::TreeBuilder::XPath->new;
  $tree->parse_file( "mypage.html");
  my $paraelements= $tree->findnodes( '//p') ;

  for my $node (@$paraelements)  {
      say $node->as_HTML() ;
  }

它返回对列表ARRAYREF的引用。要返回列表,请在变量前面加一个@,告诉Perl将其作为列表的[location/memory address],就像JIT的示例代码一样,它返回对列表ARRAYREF的引用。要返回列表,请在变量前面加一个@,告诉Perl将其作为列表的[location/memory address],就像JIT的示例代码一样