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