抓取太平洋上海市车辆管理系统的perl脚本

#!/usr/bin/perl
#use strict;
use LWP 5.64;
use LWP::ConnCache;
use IO::Socket;
require HTTP::Cookies;


                
$remote_host = "xxx.xxx.xxx.xxx";
$remote_port = "80";


$start=0;
$stop=9999;
$med=0;


$start_all=0;
$stop_all=9999;


$prefix='%BB%A6C';

my @m=(0..9,A..Z);




        for($i=$start;$i<=$stop;$i++){
                my $postfix;

                $postfix=sprintf "%04d%s", $i;
                &get_time($prefix.$m[$med].$postfix);

        }


splice(@m,0,$med+1);




foreach my $medium( @m){

        for($i=$start_all;$i<=$stop_all;$i++){
                my $postfix;

                $postfix=sprintf "%04d%s", $i;
                &get_time($prefix.$medium.$postfix);

        }
}


sub get_time{

my $num=shift@_;


#my $browser = LWP::UserAgent->new(keep_alive =>1, timeout=>5,agent =>'GoogleSpider');
my $browser = LWP::UserAgent->new(timeout=>5,agent =>'GoogleSpider');

$cookie_jar = HTTP::Cookies->new();

$browser->cookie_jar($cookie_jar);

my $infourl='http://xxx.xxx.xxx.xxx/address.jsp?vehicle=';
	
$infourl.=$num;
$infourl.='&&fgs=3010100';
my $response = $browser->get($infourl);
#die "Response Error :", $response->status_line, "\n Aborting" unless $response->is_success;
if($response->is_success)
{
	print $num."->sucess\n\n";
	`echo $num > cnt`;
}
else 
{
	print $num."->Response Error :".$response->status_line."End.\n";
	
	`echo $num >> failure`;

	return
}
#print $response->content;


my $name=substr($num,6).'.htm';   
$name='info'.$name;

open(MYOUTFILE, ">$name"); #open for write, append


print MYOUTFILE $response->content;



}

你可能感兴趣的:(jsp,socket,脚本,perl)