3

I'm trying 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"?

brian d foy
  • 129,424
  • 31
  • 207
  • 592
planetp
  • 14,248
  • 20
  • 86
  • 160

2 Answers2

6

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.

Eugene Yarmash
  • 142,882
  • 41
  • 325
  • 378
1

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

brian d foy
  • 129,424
  • 31
  • 207
  • 592
Fayland Lam
  • 1,016
  • 8
  • 11