如何使用WWW :: Mechanize获取与正则表达式匹配的链接?

Bac*_*ass 1 perl www-mechanize

我正在尝试使用正则表达式来捕获链接,但不能.我有所有链接,但有许多链接不需要.

我所做的就是抓住所有链接: http://valeptr.com/scripts/runner.php?IM= 遵守这种模式.

我把我正在做的脚本:

use warnings;
use strict;
use WWW::Mechanize;
use WWW::Mechanize::Sleepy;

my $Explorador =

    WWW::Mechanize->new(

       agent =>
             'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030624',

       sleep => '5..20'
    );

#Proceed to access the URL to find all the links in emails
$Explorador->get("file:/home/alejandro/Escritorio/hehe.php.html");

#If you want debug DOM Document.
#print $Explorador->content();

my @links = $Explorador->links;

foreach my $link (@links) {

   # Retrieve the link URL like:
   # http://valeptr.com/scripts/runner.php?IM=0cdb7d48110375.
   my $href = $link->url;

   foreach my $s ($href) { #Aqui la expresión regular

       my @links = $s =~ qr{
                               (
                               [^B]*
                               )
                               $
                           }x;
       foreach (@links) {
           print "\n",$_;
       }
   }
} 
Run Code Online (Sandbox Code Playgroud)

PS:我想这个正则表达式会比看到的更多但却看不到.如果是这样,我会回来发一篇文章.

问题:有一堆链接,我需要知道与老板过期的链接: Http: // valeptr.com/scripts/runner.php?IM= 对于它在第19行我必须应用表达式规范.这个变量my @ links = $ Explorador-> links; 他返回所有存在的链接.但是我只想知道我上面提到的链接.此致

Zai*_*aid 6

为什么不WWW::Mechanize为你做这项工作,特别是当它可以通过提供的正则表达式过滤掉你的链接?

my @wanted_links = $Explorador->find_all_links ( 
                                     url_regex => qr{scripts/runner\.php\?IM=}
                                );
Run Code Online (Sandbox Code Playgroud)

没有for循环!