Gunnar Hjalmarsson wrote:
use LWP::UserAgent;
use CGI qw(:standard);
print header(-type => 'text/html', -charset => 'UTF-8');
#----------------------------------^^^^^^^^^^^^^^^^^^^
# Google uses UTF-8 encoding
my $url = 'http://www.google.com/search?q=traducao';
my $ua = LWP::UserAgent->new;
my $agent = $ENV{HTTP_USER_AGENT};
($agent) = $agent =~ /(.+)/; # for taint mode
$ua->agent($agent);
my $res = $ua->get($url);
die $res->status_line unless $res->is_success;
print $res->content;
That code 'works' in a technical sense.
I just read Chas's reply, though, and I wasn't aware of the fact that
Google disallow *all* automated access to their search engine.
From their terms of service at
http://www.google.com/coop/docs/cse/tos.html :
"Appropriate Conduct. You shall not ... directly or indirectly generate
queries, or impressions of or clicks on Results, through any automated,
deceptive, fraudulent or other invalid means (including, but not limited
to, click spam, robots, macro programs, and Internet agents)"
The solution above is still useful to access other web pages, whose
rejections of requests from 'libwww-perl/' agents have other motives.
After all, automated access is not always abuse.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/