How can I extract all links from a page except one using Perl WWW :: Mechanize?

I am trying to use WWW :: Mechanize to extract some links from an HTML page using a method find_all_links(). It supports matching by these criteria:

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

How can I extract all links except that have the text "xyz"?

+3
source share
2 answers

You can use criteria 'text_regex':

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

See perldoc perlre for more information on negative expectation.

+6

, "grep", , ?

+1

Source: https://habr.com/ru/post/1738652/


All Articles