kazak has asked for the wisdom of the Perl Monks concerning the following question:
First of all, thanks everyone for your help.
1.Client used up all traffic on rented proxies, without warning me about it, so LWP::UserAgent was not able to use rented parent-proxies.2. In http://proxy... link, last slash was missing, I tried to add it\delete it but it was useless due to a "traffic issue", when this issue was resolved, I added the slash again and... voila, it works! In other words:
May be it's not supposed to be an issue, but for me it works somehow only with closing slash, atleast when I tried it. I have some remote proxies for my needs, and I'm trying to use them simultaneously. Script should to change proxy used for serving requests before each new request. Proxy IP's are stored in array and then should be chosen randomly. I tried this appoach for UserAgent rotation and it worked, but it's not working for for proxy rotation. I hope some one can help me with this, thanks in advance.my $cur_proxy = "http://$valid_routes[$j]"; # <--- Not working; my $cur_proxy = "http://$valid_routes[$j]/"; #<--- Works as a charm
my (@agents, @raw_routes, @valid_routes); open( AGENTS, "<", "/etc/squid/ua.cfg" ); while( <AGENTS> ) { s/#.*//; next if /^(\s)*$/; chomp; push @agents, $_; } close(AGENTS); open( ROUTES, "<", "/etc/squid/repeater/lib/routes.cfg" ); while( <ROUTES> ) { s/#.*//; next if /^(\s)*$/; chomp; push @raw_routes, "$_,ENABLED"; } close(ROUTES); my $ua = LWP::UserAgent->new(); sub cb { my($request, $ua, $h) = @_; $#valid_routes = -1; my $i = $#agents + 1; $i = rand($i); $i = int $i; foreach my $item (@raw_routes) { $item =~ s/,ENABLED//; push @valid_routes, $item unless $item =~ m/DISABLED/; } my $j = $#valid_routes + 1; $j = rand($j); $j = int $j; my $cur_agent = $agents[$i]; my $cur_proxy = "http://$valid_routes[$j]"; $request->proxy_authorization_basic( 'uname', 'passwd'); $ua->proxy(['http'], $cur_proxy); $request->header('User-Agent' => $cur_agent); $ua->timeout(120); } $ua->add_handler( request_preprepare => \&cb, { m_method => 'GET' } );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Proxy link rotation
by JavaFan (Canon) on Jan 27, 2012 at 15:28 UTC | |
by kazak (Beadle) on Jan 27, 2012 at 16:08 UTC | |
by JavaFan (Canon) on Jan 27, 2012 at 23:16 UTC | |
by kazak (Beadle) on Jan 28, 2012 at 08:50 UTC | |
by JavaFan (Canon) on Jan 28, 2012 at 12:07 UTC | |
|
Re: Proxy link rotation
by OlegG (Monk) on Jan 27, 2012 at 17:33 UTC | |
by kazak (Beadle) on Jan 27, 2012 at 21:14 UTC | |
by OlegG (Monk) on Jan 28, 2012 at 04:43 UTC |