用Perl實現網站自動登入

來源:互聯網
上載者:User

#!/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;
}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.