简体   繁体   English

如何使用Perl的WWW :: Mechanize从页面中提取所有链接(不包括一个链接)?

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

I'm trying to use WWW::Mechanize to extract some links from the HTML page using find_all_links() method. 我试图使用WWW :: Mechanize使用find_all_links()方法从HTML页面提取一些链接。 It supports matching on these criterias: 它支持根据以下条件进行匹配:

  • text 文本
  • text_regex text_regex
  • url 网址
  • url_regex url_regex
  • url_abs url_abs
  • url_abs_regex url_abs_regex
    ... ...

How can I extract all links except one that has text "xyz"? 我如何提取具有文本“ xyz”的链接以外的所有链接?

You can use the 'text_regex' criteria: 您可以使用'text_regex'条件:

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

See perldoc perlre for more on negative look-ahead assertion. 有关否定的前瞻性断言的更多信息,请参见perldoc perlre

为什么不获取所有链接,然后使用'grep'跳过不需要的链接?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM