commit 1a49e257d43e118e3a8aa00eb28bff1431553a07 parent 10a92028d7d9f497530711452712e5569f583328 Author: Kyle Milz <kyle@getaddrinfo.net> Date: Sun, 22 Mar 2015 17:21:55 -0600 PriceChart: scrape from different addresses if possible Diffstat:
M | PriceChart.pm | | | 13 | ++++++++++++- |
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/PriceChart.pm b/PriceChart.pm @@ -91,8 +91,19 @@ sub new_ua { my $cfg = shift; my $verbose = shift || 0; + my $ua; + + # it's optional to list ip addresses to scrape on + if ($cfg->{addresses}) { + my @addresses = split(" ", $cfg->{addresses}); + my $addr = $addresses[rand @addresses]; + print "info: new_ua: using $addr, $addr_total total\n" if ($verbose); + $ua = LWP::UserAgent->new(local_address => ); + } + else { + $ua = LWP::UserAgent->new(); + } - my $ua = LWP::UserAgent->new(); $ua->default_header("Accept" => "*/*"); $ua->default_header("Accept-Encoding" => scalar HTTP::Message::decodable()); $ua->default_header("Accept-Charset" => "utf-8");