开发者

How can I extract all links from the page excluding one using Perl's WWW::Mechanize?

开发者 https://www.devze.com 2022-12-24 14:05 出处:网络
I\'m t开发者_开发知识库rying to use WWW::Mechanize to extract some links from the HTML page using find_all_links() method. It supports matching on these criterias:

I'm t开发者_开发知识库rying to use WWW::Mechanize to extract some links from the HTML page using find_all_links() method. It supports matching on these criterias:

  • text
  • text_regex
  • url
  • url_regex
  • url_abs
  • url_abs_regex

    ...

How can I extract all links except one that has text "xyz"?


You can use the 'text_regex' criteria:

$mech->find_all_links(text_regex => qr/^(?!xyz$).*$/);

See perldoc perlre for more on negative look-ahead assertion.


Why not get all links then use 'grep' to skip those you don't need?

0

精彩评论

暂无评论...
验证码 换一张
取 消