$resp = $ab->request(HTTP::Request->new(GET => $url));
$rrs = $resp->content;
while(($rrs =~ m/<a href=\"https?:\/\/(.*?)\//g) && ($rrs =~ m/<a href=\"?http:\/\/(.*?)\//g)){
您的示例中断了,但是您似乎想要获取资源,提取链接并可能要执行其他操作。我建议您让Mojolicious为您执行此操作。它可以获取资源,解析HTML(dom
),提取其他链接(在map
中),然后选择具有正确方案的链接(第一个grep
):
use v5.10;
use Mojo::UserAgent;
my $ua = Mojo::UserAgent->new;
my @queue = ( $ARGV[0] );
my %Seen; # don't process things we've already seen
while( my $this = shift @queue ) {
say "Processing $this";
my $tx = $ua->get( $this );
my @links = $tx->result
->dom
->find( 'a' )
->map( attr => 'href' )
->grep( sub { Mojo::URL->new($_)->scheme =~ /https?/ } )
->grep( sub { ! $Seen{$_} } )
->each;
say "\t", join "\n\t", @links;
push @queue, @links;
}
我在Mojolicious Web Clients中用很多示例编写了所有这些内容。