What is this Perl code using LWP :: UserAgent?

I have this code:

use strict;
use LWP::UserAgent;
use warnings;
my $ua = new LWP::UserAgent(agent => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.5) Gecko/20060719 Firefox/1.5.0.5');
$ua->proxy([qw(http https)] => 'http://59.39.92.148:1080');
my $response = $ua->get("http://www.google.com");
print $response->code,' ', $response->message,"\n";

      

Is the meaning of the code "open www.google.com with a proxy"? What is the explanation?

+2


a source to share


3 answers


It creates an LWP :: UserAgent object .

Finally:



print $response->code,' ', $response->message,"\n";`

      

allows you to return a response to the user

I am a C # developer but it looks like this :)

+2


a source


The code creates an LWP :: UserAgent object to disguise itself as a human browser to bypass Google's spider detection mechanism. In doing so, it violates Google's Terms of Service :

5.3. You agree not to access (or attempt to access) any of the Services by any means other than through an interface provided by Google, unless you are permitted to do so in a separate agreement with Google. You specifically agree not to access (or attempt to access) any of the Services by any automated means (including the use of scripts or web crawlers) and must comply with the instructions set out in any robots.txt file present on the Services.

59.39.92.148

is probably some compromised (or poorly configured) open proxy in China. The set $ua

to use is an attempt to hide the beginning of the TOS violation.



By the way, you should know that the server 59.39.92.148

will be able to register and track all your requests and responses if you decide to go this route.

The more important question is, what are you trying to do?

+2


a source


Looks like: open "www.google.com" with an HTTP proxy

0


a source







All Articles