hey monks im having some trouble processing websites in parallel when the link redirects.. have a look at my code
#!/opt/csw/bin/perl -w
print "Content-type: text/html\n\n";
require LWP::Parallel::UserAgent;
use HTTP::Request;
$timeout = 10;
my @ns_headers = (
'User-Agent' => 'Mozilla/4.76 [en] (Win98; U)',
'Accept' => 'text/html, text/plain,',
'Accept-Charset' => 'iso-8859-1,*,utf-8',
'Accept-Language' => 'en-US',
);
my $reqs = [
HTTP::Request->new('GET', "http://www.google.ca", [@ns_headers]),
HTTP::Request->new('GET', "http://advertising.microsoft.com/micros
+oft-adcenter?s_int=US_20070401_livesearchResults_smh_001", [@ns_heade
+rs]),
####UN-COMMENT THIS and it wont work ###### HTTP::Request->new('GET',
+"http://advertising.microsoft.com/search/", [@ns_headers]),
];
my $pua = LWP::Parallel::UserAgent->new();
$pua->in_order (1); # handle requests in order of registration
$pua->duplicates(0); # ignore duplicates
$pua->timeout (2); # in seconds
$pua->redirect (1); # follow redirects
foreach my $req (@$reqs) {
print "Registering '".$req->url."'<BR>\n";
if ( my $res = $pua->register ($req) ) {
print STDERR $res->error_as_HTML;
}
}
my $entries = $pua->wait();
foreach (keys %$entries) {
my $res = $entries->{$_}->response;
print "Answer for '",$res->request->url, "' was \t", $res->code,":
+ ", $res->message,"<BR>\n";
print "and the content is<BR>\n";
print "---------------------------<BR><TEXTAREA NAME='asdasd' ROWS
+='5' COLS='80' WRAP='virtual'>\n";
print $res->content;
print "</TEXTAREA>---------------------------<BR>\n";
}
by the way this code was taken from a website as an example here is where i found it http://search.cpan.org/~marclang/ParallelUserAgent-2.57/lib/LWP/Parallel.pm
update:
i'm new to perl, i have java knowledge and am applying it as best as i can to perl, i have no idea how to get any error messages. what's going wrong i think is the line:
my $entries = $pua->wait();
i think that may be the problem, because nothing executes after that. if i input valid links in the requests the program runs fine and just prints out the content of the website. if i input a link that redirects to another link, then my program freezes up. thats about as best as i can describe my problem. like i said this code isn't fully mine, and im having trouble understanding it
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.