需要抓取一批同事的邮箱地址,然后批量给他们发送邮件。就用lwp模块写了一个
- #!/usr/bin/perl
-
use warnings;
-
use strict;
-
use LWP;
-
my $key;
-
my $email;
-
open IN,"<$ARGV[0]" or die "can't open $ARGV[0]";
-
while($key=<IN>) {
-
$email=&getmail($key);
-
-
if($email ne 0) {
-
chomp($key);
-
printf("%s\t%s\n",$key,$email);
-
}
-
}
-
sub getmail() {
-
my $PID=getppid();
-
my $TEMP='/tmp/page.'.$PID;
-
open FILE_W,">$TEMP" or die "open file $TEMP fro writing failed.\n";
-
my $url='';
-
my $name=shift;
-
$url =$url . $name;
-
my $browser = LWP::UserAgent->new;
-
$browser->ssl_opts(verify_hostname=>0);
-
my $response= $browser->get($url);
-
print FILE_W $response->content;
-
close FILE_W;
-
open FILE_R ,"<$TEMP" or die "open file $TEMP for reading failed.\n";
-
my $line;
-
while($line=<FILE_R>) {
-
if ($line=~/mailto/) {
-
if( $line=~/>([\w\.]+\@XXXXX\.com)</ ) {
-
return $1;
-
}
-
# last;
-
}
-
}
-
close FILE_W;
-
unlink $TEMP;
-
return 0;
-
}
阅读(1013) | 评论(0) | 转发(0) |