usr bin perl use Encode use Text Iconv use LWP UserAgent ua LWP UserAg

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/perl
#use Encode;
use Text::Iconv;
use LWP::UserAgent;
$ua = LWP::UserAgent->new;
$ua->agent("MyApp/0.1 ");
# Create a request
my $req = HTTP::Request->new(POST => 'http://www.yandex.ru/');
$req->content_type('application/x-www-form-urlencoded');
$req->content('query=libwww-perl&mode=dist');
# Pass request to the user agent and get a response back
my $res = $ua->request($req);
# Check the outcome of the response
if ($res->is_success) {
#print $res->content;
$text = $res->content;
$converter = Text::Iconv->new("utf-8", "koi8-r");
$b = $converter->convert($text);
print $b;
}
else {
print $res->status_line, "\n";
}