自動搜尋google

自動搜尋google



[Copy to clipboard] [ - ]
CODE:
use LWP::UserAgent;
$ua = LWP::UserAgent->new;
$ua->agent("MyApp/0.1 ");

# Create a request
my $req = HTTP::Request->new(GET => 'http://www.google.com.tw/search?q=%E4%B8%AD%E6%96%87&ie=utf-8&oe=utf-8');

# 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;
}
else {
   print $res->status_line, "\n";
}

請問上面代碼怎麼修改成可以輸入要搜尋的字符串 & 輸出成 HTML 文件?


謝謝
知道上面代码的朋友可以说一下吗?

谢谢
放弃吧,很久以前Google就不吃这一套了
search "Google" on CPAN
#!c:\perl\bin\perl -w
use strict;
use LWP;
use IO::File;
use URI;
use HTTP::Request::Common qw(GET);
use Content;
my $url="http://www.google.cn/search";
&google($url);
sub google
{
my $url=shift;
my $search_url=URI->new($url);
my $ua = LWP::UserAgent->new;
$ua->agent("Yenibot/1.0" . $ua->agent);
$ua->env_proxy;
$search_url->query_form(
'q'=>'DNA','meta'=>'','complete'=>'1','h1'=>'zh-CN',
);
my $response =  $ua->get($search_url);
my $content=$response->content();
my $h=new IO::File(">>c:\\hao123.html");
$h->print($content);
}
检索内容存在,c:\hao123.html里!
Can't locate Content.pm in @INC (@INC contains: C:/Perl/site/lib C:/Perl/lib .)
at C:\thrth.pl line 7.
BEGIN failed--compilation aborted at C:\thrth.pl line 7.

Content.pm?? 这要怎么安装?

Cpan > install Content 好像不对
另一个方法是Win32::OLE, 只要IE能做它就能, 无须额外Module
CPAN也有在其上封装好的IE Automation
不好意思的,那个use Content是多余的,把use Content去掉就可以了!这是从其他模块中挑出的程序,可能当时忘了删了!应该没事了,我自己已经试了!
OK... 感谢