i5513 has asked for the wisdom of the Perl Monks concerning the following question:
Hi monks,
First, I cannot install LWP::Parallel::UserAgent (it is not installable in debian sid). I would like to solve this problem without any other module (WWW::Mechanize ..., and other modules which can be found searching in the monastery).
How can I simulate next code in perl (just rewriting wget command with LWP module) ?use threads; my $user="xxx"; my $password="yyy"; sub my_thread_sub { my ($url)=@_; my $cookie=to_string ($url); # to string convert url to an acceptable +filename my $WGET; if ( -e $cookie ) { open $WGET, "wget -q -O - -w 1 -T 1 -t 1 --load-cookies $cookie -- +user $user --password $password $url |"; } else { open $WGET, "wget -q -O - -w 1 -T 1 -t 1 --save-cookies $cookie -- +keep-session-cookies --user $user --password $password $url |" } local $/; $output=<$WGET>; ... return 0; } my @thrs; my @urls=qw("http://example1/" "http://example2/"); dontgo: my $i=0; foreach my $url (@urls) { $thrs[$i]=threads->new ("my_thread_sub",$url); $i++; } foreach my $thr (@thrs) { $thr->join; } sleep 3 goto dontgo; exit 0;
I tried to simulate it with LWP, but I fail when I want to load the previous cookie file (lwp saves always an empty cookie file).
I tried too loading file from wget cookie file, but lwp removes the content. I would like to maintain the http session in each url, and I wouldn't like to have running threads all the time (that is the other option)
So, without pointing me to another module (aka Threads::Pool), how can I s/wget/lwp/ in this case ?
Thank you very much !
|
|---|