ronstudio has asked for the wisdom of the Perl Monks concerning the following question:
use Mojo::UserAgent; use Mojo::IOLoop; my @urls = ( 'mojolicious.org/perldoc/Mojo/DOM', 'mojolicious.org/perldoc/Mojo', 'mojolicious.org/perldoc/Mojo/File', 'mojolicious.org/perldoc/Mojo/U +RL' ); my $ua = Mojo::UserAgent->new(max_redirects => 5); $ua->transactor->name('MyParallelCrawler 1.0'); my $delay = Mojo::IOLoop->delay; my $fetch; $fetch = sub { return unless my $url = shift @urls; my $end = $delay->begin; $ua->get($url => sub { my ($ua, $tx) = @_; say "$url: ", $tx->result->dom->at('title')->text; $end->(); $fetch->(); }); }; #Process two requests at a time $fetch->() for 1 .. 2; $delay->wait;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: coderef for 1 .. 2?
by kcott (Archbishop) on Nov 01, 2017 at 07:59 UTC | |
by ronstudio (Novice) on Nov 01, 2017 at 10:08 UTC | |
by kcott (Archbishop) on Nov 01, 2017 at 19:41 UTC | |
by ikegami (Patriarch) on Nov 01, 2017 at 23:12 UTC | |
|
Re: coderef for 1 .. 2?
by Anonymous Monk on Nov 02, 2017 at 01:55 UTC | |
by ronstudio (Novice) on Nov 02, 2017 at 03:17 UTC | |
by ronstudio (Novice) on Nov 02, 2017 at 07:34 UTC | |
by Anonymous Monk on Nov 02, 2017 at 13:16 UTC |