perl - Perl While 循环 Http 和 HTTPS 响应
问题描述
$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
)、提取其他链接 (in map
),并选择具有正确方案的链接 (first 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中写了很多例子。
推荐阅读
- azure - VSCode - 部署 Azure 应用 - 找不到任务错误
- ios - 在 SwiftUI 卡片视图中将 UIImage 裁剪到跨设备的特定区域
- angular - 如何在代码中创建角度模板引用
- laravel - Laravel Spatie 的媒体库:如何下载多个文件并将它们压缩到一个目录中
- html - 如何从 regex101 任务 8 中的字符串中去除所有 HTML 标签?
- c - 如何实现fillpoly函数
- python - 从 PyQt5 中的 QTableWidget 中删除单元格填充
- c++ - 从二进制问题转储文件
- discord.py - Discord Python - 如何让机器人在 if message.content 下接收消息
- python - 随机数生成器 (Python)