This is more of a theory question, but I'm curious what would be the faster of the three to integrate into a recursive screen-scraping engine; LWP::Parallel, HTTP::GHTTP, or raw IO::Socket code wrapped around some regexen and URI/URI::URL code..

I'm doing some benchmarking of LWP::Parallel::UserAgent right now, and noticing that successive tests against the same site yield some very different results. Could this be site-related? Local bandwidth-related? Module-related?

Along these lines, what would be the fastest way to get content which passes a 200 or 302 response code (assuming the site is up, responding, and the content is valid)?

Here's what I have so far to test this:

use strict; use Data::Dumper; use LWP::Parallel::UserAgent; use HTTP::Request; use HTML::SimpleLinkExtor; use LWP::Parallel::Protocol::http; *LWP::Parallel::UserAgent::_new_response = \&LWP::UserAgent::_new_response; my $pagecount = 1; my $url = $ARGV[0]; my $request = HTTP::Request->new(GET => $url); my $browser = 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4b) Gecko/20030514'; my $ua = new LWP::UserAgent; $ua->agent($browser); # debugging messages. See 'perldoc LWP::Debug' # use LWP::Debug qw(+); my $response = $ua->request($request); my $status_line = $response->status_line; my $html = $response->content; my $extor = HTML::SimpleLinkExtor->new(); $extor->parse($html); my @img_srcs = $extor->img; my @a_hrefs = $extor->a; my @base_hrefs = $extor->base; undef my %saw; my @out = grep(!$saw{$_}++, @a_hrefs); my @urls; my $uri = URI->new($url)->canonical; my $host = $uri->host($url); my $g_scheme = $uri->scheme; foreach my $site (@out) { my $p_uri = URI->new($site)->canonical; my $p_scheme = $p_uri->scheme; if ($p_scheme !~ /http/) { $site =~ s,^//,http://,; $site = "$g_scheme://$host/$site\n\n"; } push @urls, $site; } my $reqs = [ map { HTTP::Request->new('GET', $_ ) } @urls ]; my $pua = LWP::Parallel::UserAgent->new(); $pua->in_order (0); $pua->duplicates(1); $pua->timeout (2); $pua->max_req (100); $pua->max_hosts (100); $pua->redirect (1); my $urlcount = 0; foreach my $req (@$reqs) { if ( my $res = $pua->register ($req) ) { print STDERR $res->error_as_HTML; } $urlcount++; } print "Total valid (unique) urls found: $urlcount\n\n"; my $entries = $pua->wait(); foreach (keys %$entries) { my $res = $entries->{$_}->response; my $html = $res->content; print "Fetching link $pagecount\n\n"; open FILE, ">$pagecount.html" or die $!; print FILE $html; close FILE; $pagecount++; }

This code snippet works as-is (there's much more code not included in this, irrelvant for this node), but running this code multiple times against a host, one after the other, seems to yield very different fetch times. The log also seems to periodically report some warnings (errors?) about being out of bandwidth. I've got plenty, and the sites I'm hitting are very small with very small Content-Length values.

LWP::Parallel::UserAgent::_check_bandwith: No open request-slots available LWP::Parallel::UserAgent::_make_connections_unordered: Not enough bandwidth for request

Thoughts? Comments? Suggestions?


In reply to LWP::Parallel vs. HTTP::GHTTP vs. IO::Socket by hacker

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.