How can I extract URL and link text from HTML in Perl?

后端 未结 11 1680
一生所求
一生所求 2020-11-27 17:19

I previously asked how to do this in Groovy. However, now I\'m rewriting my app in Perl because of all the CPAN libraries.

If the page contained these links:

<
11条回答
  •  忘掉有多难
    2020-11-27 17:57

    Another way to do this is to use XPath to query parsed HTML. It is needed in complex cases, like extract all links in div with specific class. Use HTML::TreeBuilder::XPath for this.

      my $tree=HTML::TreeBuilder::XPath->new_from_content($c);
      my $nodes=$tree->findnodes(q{//map[@name='map1']/area});
      while (my $node=$nodes->shift) {
        my $t=$node->attr('title');
      }
    

提交回复
热议问题