您的位置:首页 > 运维架构 > 网站架构

用Perl实现网站自动登录

2011-11-07 22:38 274 查看
#!/usr/bin/perl -w 

use strict;

use   LWP;

use   HTTP::Request::Common   qw(POST   GET); 

use   HTTP::Cookies;

use   LWP::UserAgent; 

use   LWP::Simple; 

use   URI::URL;

my   $ua   =   LWP::UserAgent-> new; 

$ua-> agent( "Mozilla   1.503   Windows   XP "); 

$ua->cookie_jar(HTTP::Cookies->new(file => "bankcookies.txt", autosave => 1)); 

my   $url = "http://www.ebigear.com/login.html"; 

my   $req = POST   $url,[MemberName=>"thinkhy",Pwd=>"******"]; 

my   $response = $ua-> request($req); 

die "Can't get $url -- ", $response->status_line

   unless $response->is_success;

die "Hey, I was expecting HTML, not ", $response->content_type

   unless $response->content_type eq 'text/html';

my   $loginReq = $response-> content; 

if ($loginReq =~ m/成功/sg) {

    print "登录成功\n";

}

else {

    print "登录失败\n";

}

#print  $response->head;

# Header

my @ns_headers = (

  );

$response  = $ua->get('http://www.ebigear.com/resdown-1393-7777700044624.html', @ns_headers);

my $content = $response->content;

if ($content =~ m/因您未登录/sg) {

    print "哎,不能获取到mp3地址\n";

}

else {

    print "成功获取到mp3地址\n";

}

if ($content =~ m/(<div class="downloadurl">).*?"(ftp:\/\/.*?)"/sg) {

    print "get it: $2\n";

    $url = $2;

    my($user,$password,$site,$path,$file) = ($url =~ /^ftp:\/\/(.*?):(.*?)@(.*?)(\/.*)\/(.*)$/s); 

    print "user:$user\npwd:$password\nsite:$site\npath:$path\nfile:$file\n";

    if ($ua->is_protocol_supported('ftp'))

    {

        print "支持\n";

        $response  = $ua->get($url, @ns_headers);

        print "$url";

        getstore $url,"1.mp3";

    }

#    my $ftp;

#$ftp = Net::FTP->new("$site", Debug => 0)

#      or die "Cannot connect to $site: $@";

#    $ftp->login("$user","$password")

#      or die "Cannot login ", $ftp->message;

#    $ftp->cwd("$path")

#          or die "Cannot change working directory ", $ftp->message;

#    $ftp->get($file)

#$ftp->get("ftp://18_zhi:www.daerduo.cn\@playjd.teacherhome.cn:181/c77e/SID-H777/SID77777/RID-TT5/RID-H47/7777700044624tqyp.MP3")

#      or die "get file failed ", $ftp->message;

#    $ftp->quit;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  perl url mozilla file user path