#!/usr/bin/env perluse Mojolicious::Lite;get '/random-urls' => sub {my $c = shift;$c->render_later;$c->delay(sub { ## first stepmy $delay = shift;$c->ua->get('https://www.random.org/bytes/', $delay->begin);$c->ua->get('https://www.random.org/integer-sets/', $delay->begin);$c->ua->get('https://www.random.org/strings/', $delay->begin);$c->ua->get('https://www.random.org/audio-noise/', $delay->begin);},sub { ## second stepmy $delay = shift;for my $dom (map { $_->res->dom } @_) {say STDERR $dom->at('title')->text;}$c->render(text => "Got all the links");});};app->start;
Here is how you can fetch simultaneously many urls, check if every response is 200 OK and print title tags (or catch an exception if something goes wrong) .
If you're not familiar with promises, here is a perfect
documentation
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise
# cpanm Mojo::Pua
use Evo 'Mojo::Pua want_code; Mojo::Promise all';
my $ua = Mojo::Pua->new;
my @urls = qw(http://alexbyk.com https://metacpan.org
https://www.perl.org);
all(map { $ua->get($_)->then(want_code 200)->then(sub {
shift->dom->at('title') }) } @urls)
->spread(sub(@titles) { say $_ for @titles })
->catch(sub($e) { warn $e })->finally(sub {
Mojo::IOLoop->stop });
Mojo::IOLoop->start;
Throttling requests is a little bit more complex
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious...@googlegroups.com.
To post to this group, send email to mojol...@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the Google Groups "Mojolicious" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mojolicious/wdp_pgd4e0k/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mojolicious+unsubscribe@googlegroups.com.
I'm not an expert, but what you're asking for looks like a job
for Minion: https://metacpan.org/pod/Minion
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscribe@googlegroups.com.
To post to this group, send email to mojol...@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and all its topics, send an email to mojolicious...@googlegroups.com.
To post to this group, send email to mojol...@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious...@googlegroups.com.
To post to this group, send email to mojol...@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the Google Groups "Mojolicious" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mojolicious/wdp_pgd4e0k/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mojolicious...@googlegroups.com.
To unsubscribe from this group and all its topics, send an email to mojolicious+unsubscribe@googlegroups.com.
I've found the exact example I needed. Unfortunately, it is commented and described in Russian. I did not need nothing like minion
You are asking too abstract question and trying to get too specific answer.
If you want an example that works for you, provide a details:
what sites do you want to parse, where they come from, why do you
need to throttle download queue, what exactly r u trying to limit
(max connections at a time, max kicks per a time unit) and how
(per link, per host, per ip, per subnet).
--