#!/usr/bin/perl -w# Gist: https://gist.github.com/2928006use LWP::Simple;my $url=$ARGV[0];my $filename =$ARGV[1]; my $content = get($url) or die "Couldn't get $url";
#$content =~ s#^.*?(<div.*?</div>).*$##m;
if ($content =~ m#.*(<div id="enText" style="display:block">.*?</div>).*#sg) { $text = $1;
# 開啟模板檔案 open(TEMPLATE, "template.html") or die " Couldn't open template.html for writing: $! " ;
# 讀模數板檔案 $/="</html>"; # 讀到</html>結束 my $reads = <TEMPLATE>;
# 替換聽力文本 $reads =~ s/==TEXT_CONTENT==/$text/gix; #print $reads;
# 輸出html檔案 open (OUT , " > $filename " ) or die " Couldn't open $filename for writing: $! "; print OUT $reads;
# 下載聽力 my $baseUrl = $url; $baseUrl =~ s/(.*)(//.*/.html)/$1/g; my $reslink = $content; $reslink =~ s/.*<a href="(.*?)" title="進入下載資料頁面">下載聽力<//a>.*/$1/sg; $reslink = $baseUrl . "/" . $reslink;
print "/nreslink:",$reslink,"/n"; my $respage = get($reslink) or die "Couldn't get $reslink";
my $mp3link = $respage; print $mp3link;#$mp3link =~ s#.*<a href="(.*?)" target="_blank"><img src="/images/downloadurl1/.jpg"></a>.*#$1#sg;#if ($mp3link =~ m/.*<a href="(.*?)" target="_blank"><img src="//images//downloadurl1/.jpg"><//a>.*/sg) {
# 沒登入,下載連結擷取不到,怎麼辦? if ($mp3link =~ m/downloadurl1/sg) { print "匹配/n"; } else { print "不匹配/n"; } #<a href="(.*?)" target="_blank"><img src="/images/downloadurl1.jpg"></a>
print "/ndownload:".$reslink."/n";}else { print "不匹配/n";}