#!D:\Perl\bin\perl.exe -w
use strict;
use LWP;
use HTML::Parser;
our $cache_file = 'search_resule.html';
sub get_file_name{
my $filename = shift@ARGV;
my $index = index($filename,'_');
$filename = substr($filename,$index + 1);
}
sub search{
my $url = 'http://www.baidu.com/s?wd='.get_file_name;
my $browser = LWP::UserAgent->new;
my $respone = $browser->get($url);
if($respone->is_success){
open OUTFILE,">$cache_file" or die "cannot open cache_file";
print OUTFILE $respone->content;
close OUTFILE;
}else{
print "error:".$respone->status_line."\n";
}
}
sub print_info{
open FF,"<$cache_file" or die "cannot open cache_file";
while(<FF>){
my $bool = 0;
if(/^<table.*>/ || $bool == 1){
s/<\/font>/\n/g;
s/.*百度快照.*/--------------------------------------------------------------------------------------------/g;
s/<.+?>//g;
print;
}
if(/下一页/){ $bool = 0; }else{$bool = 1;}
}
close(FF);
}
search;
print_info;
unlink($cache_file);
print "[+]done!\n";
<>