Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5272565
  • 博文数量: 1144
  • 博客积分: 11974
  • 博客等级: 上将
  • 技术积分: 12312
  • 用 户 组: 普通用户
  • 注册时间: 2005-04-13 20:06
文章存档

2017年(2)

2016年(14)

2015年(10)

2014年(28)

2013年(23)

2012年(29)

2011年(53)

2010年(86)

2009年(83)

2008年(43)

2007年(153)

2006年(575)

2005年(45)

分类: LINUX

2009-03-18 23:54:41

Perl模拟浏览器(cookie)抓Email

关键字: email perl
Perl代码 复制代码
  1. #!/usr/bin/perl -w   
  2.   
  3.   
  4. #use CGI qw(:standard);   
  5. use LWP::UserAgent;   
  6. use HTTP::Request::Common;   
  7. use HTTP::Request::Common qw(POST);   
  8. #$e=exp(1);   
  9. open(OPENFILE,"keyword.txt") or die("open file failure!");   
  10. #$/=undef;   
  11. #$cgi=new CGI;   
  12. #print $cgi->header;   
  13. $email="email.txt";   
  14. $k=1;   
  15. while($line=){   
  16.        
  17.     #if($line=~s/##[0-9a-zA-Z]+##/$e/){   
  18.     #    print $line;   
  19.     #   }   
  20.        #else   
  21.        #{   
  22.        #    print $line;   
  23.         #}   
  24.         #print $line;   
  25.         if($line){   
  26.             
  27.              
  28.         $line=~s/\n|\r/ /ig;   
  29.         $line=~s/\s+$//ig;   
  30.         if( -e $email )   
  31.         {   
  32.             open(SRC,">>$email");   
  33.         }   
  34.         else{   
  35.             open(SRC,">$email");   
  36.         }   
  37.         $email1=getEmail($line);   
  38.         if($email1){   
  39.             print SRC "$line\t$email1\r\n";    
  40.             }   
  41.         else{   
  42.             printf SRC "$line\r\n";    
  43.             }   
  44.         close(SRC);    
  45.         sleep(10);   
  46.         if($k%8==1){   
  47.         `wget `;   
  48.         }   
  49.         print "$k\n";   
  50.         $k++;   
  51.         }   
  52.        
  53. }   
  54. print "Total Record:\$";   
  55. close(OPENFILE);   
  56. #$slurp=;   
  57. sub getEmail{   
  58. my $agent=LWP::UserAgent->new;   
  59. my @header=(   
  60. 'User-Agent'=>'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; iCafeMedia; .NET CLR 2.0.50727; CIBA)',   
  61. 'Accept' => '*/*',   
  62. 'Accept-Charset' => 'gzip, deflate',   
  63. 'Accept-Language' => 'zh-cn',   
  64. 'Cookie'=> 'Tango_UserReference=38D8FF1624305B16496E9808; MTCCK=1; _csuid=48feeef505683659; cookmcnt=999; CID=1459382; cookMemberName=YunFan; cookMemberID=61448; savedEmail=liyunfan@genscriptcorp.com; DLDExec=OK; __utma=232384002.1655516880.1231991960.1231994793.1232000250.3; __utmb=232384002; __utmc=232384002; __utmz=232384002.1231991960.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none)'  
  65. );   
  66. my $url="/allsearch.taf?_function=headersearch&SearchParam=$_[0]&SearchType=Company";   
  67. #print $_[0]."\n";   
  68. #my $arg={'SearchParam'=>"$_[0]",'SearchType'=>'Company'};   
  69. #print $arg->{SearchParam}."\n";   
  70. my $temp2="";   
  71. my $temp="",$temp1="";   
  72. #my $req=HTTP::Request->new(GET=>"$url",@header);   
  73. my $res =$agent->get($url,@header);   
  74. my $content="";   
  75. #my $res =$agent->post($url,$arg,'Content_Type' => 'form-data');   
  76. #request($req);get($url,@header);   
  77. if($res->is_success){   
  78.     $content= $res->content;   
  79.     #print "test";   
  80.     #$content=~s/\s+|>|<|\///ig;   
  81.     #print $content;   
  82.        while($content=~/company.taf\?_function=detail&Company_uid1=(\d+)&_UserReference=(\w+)/ig)   
  83.        {   
  84.             $temp=$1;$temp1=$2;   
  85.             if($temp and $temp1){   
  86.                 $url='/company.taf?_function=detail&Company_uid1='.$temp.'&_UserReference='.$temp1;   
  87.                 $content=~s/http:\/\/www\.lead411\.com\/company\.taf\?_function=detail\&Company_uid1=$temp\&_UserReference=$temp1//ig;   
  88.                 print $url."\n";   
  89.                 $res =$agent->get($url,@header);   
  90.                 if( $res->is_success)   
  91.                 {   
  92.                 $content=$res->content;   
  93.                 $content=~s/\s+|>|<|\///ig;   
  94.                 $content=~s/\s+//ig;   
  95.                 $i=0;$temp="";   
  96.                 do{   
  97.                    $i=index($content,'CEO',$i);   
  98.                    $temp=substr($content,$i,150);   
  99.                    #print $temp;   
  100.                    if($temp=~/"mailto:(.*)"font/ig){   
  101.                         $temp2.=$1;   
  102.                         print $_[0]."---------------".$temp2."\n";   
  103.                    }   
  104.                      
  105.                    if($i!=-1){   
  106.                         $i=$i+150;   
  107.                    }   
  108.                    else{   
  109.                         $i=0;   
  110.                     }   
  111.                 }while($i)   
  112.                 #print $content;   
  113.                    
  114.                 #if($content=~/(.*?CEO.*?<\/TD> .*?mailto:"[A-Z0-9._%-]+\@[A-Z0-9._%-]+\.[A-Z]{2,4}"<\/TD>)/ig)   
  115.                 #{   
  116.                 #   print "test $1";   
  117.                 #}   
  118.                 #print $content;   
  119.                 #$temp=~/mailto:"[A-Z0-9._%-]+\@[A-Z0-9._%-]+\.[A-Z]{2,4}"/ig;                   
  120.                    
  121.             }   
  122.            
  123.             }   
  124.         }   
  125.     }   
  126.     return $temp2;   
  127. }   
  128.        
  129. exit;  
阅读(3830) | 评论(1) | 转发(0) |
0

上一篇:自动找proxy刷广告代码

下一篇:学习学习

给主人留下些什么吧!~~

chinaunix网友2009-03-23 23:11:22

好!写的不错吗!交个朋友吧