Source

woocode / sa-auto / sh / mfork / qzone_uin.pl

#!/usr/bin/perl
#####################################################
$save_base_path = '/apps/dat/qzone_uin_5/';

require HTTP::Request;
require HTTP::Response;
require HTTP::Headers;
require HTTP::Cookies;
require LWP;

use File::Path;




&init;
&main;

sub init{
  $cookie_jar = HTTP::Cookies->new;
}

sub get{

	my $Gua,$Gresponse;
	my ($Gurl) = @_;
	$Gua = LWP::UserAgent->new;	
	$Grequest = HTTP::Request->new(GET=>$Gurl);	
	$cookie_jar->add_cookie_header($Grequest);	
	$Gresponse = $Gua->request($Grequest);

}



sub main{

  $base_url = 'http://drift.qzone.qq.com/cgi-bin/getrecvgift?uin=';


 
  for ( $i=0; $i<1000; $i++ ) {
     $save_path = $save_base_path.$i."/";
     mkpath( $save_path );
     print "build [$save_path]\n";
  }




  $flst=$ARGV[0];

  open(RF,$flst);

  while ( $line=<RF> ){
    chop($line);
    $url=$base_url.$line;
    $path_hash=$line % 999;

    $save_file = $save_base_path.$path_hash."/$line.xml";

    &get($url);
    $body = $Gresponse->content;
    $status_line = $Gresponse->status_line;


    if ( $status_line !~ /200 OK/ ) {
      print "[try] $url \n";
      select(undef,undef,undef,3);
      next;
    }

    print "save [$url] to  [$save_file]\n";

    open(WF, ">$save_file" );
    print WF $body; 
    close(WF);

    #select(undef,undef,undef,0.1);

  }#end while

  close(RF);

}