use LWP::UserAgent;
use autodie qw/ open close /;
use WWW::Mechanize;
use LWP::Simple qw($ua get);
use Encode;
$ua->agent('My agent/1.0');
# create WWW::Mechanize object
# autocheck 1 checks each request to ensure it was successful
my $mech = WWW::Mechanize->new();
if (-e "bgmstore.txt"){
unlink("bgmstore.txt");
}
$mech->get("http://bgmstore.net/?q_type=category&q=%EC%9C%A0%EB%A8%B8");
@link = $mech->find_all_links( url_regex => qr/view/);
for $new_link (@link){
$url = $new_link->url_abs();
$no++;
if ($no % 2 == 0 ){
print $url;
$mech->get($url);
$cont = $mech->content();
print $no." article is extracted...\n";
@files=();
$cont=encode("euc-kr", $cont);
@temp = split(/titleBox/, $cont);
@temp = split(/<span/, $temp[1]);
$subject = $temp[0];
$subject =~ s/clearfix">//;
print $subject;
$name = "땡초";
@mp3 = $mech->find_all_links( url_regex => qr/mp3/);
print $mp3[0]->url_abs();
$filename = $subject;
$filename =~ s/,//g;
$filename =~ s/\?//g;
$filename =~ s/\s+//g;
print $filename;
$mech->mirror($mp3[0]->url_abs(), $filename.".mp3");
$name = "name: ".$name;
$subject = "subject: ".$subject;
$memo = "memo: ".$memo;
open MYFILE, ">>", "bgmstore.txt" or die ;
print MYFILE "$no";
print MYFILE "------------------------------------------------------------------------------\n";
print MYFILE "$name\n";
print MYFILE "$subject\n";
print MYFILE "$memo\n";
}
}
댓글 없음:
댓글 쓰기