#!/usr/bin/perl
use HTTP::Tiny;
use Data::Dumper;
my $contrib_url="http://mirrors.ustc.edu.cn/CRAN/web/packages/available_packages_by_name.html";
my $browser=HTTP::Tiny->new();
my $response=$browser->get("$contrib_url");
my $content=$response->{"content"};
my @lines=split/\n/,$content;
my $i=0;
foreach my $line(@lines){
if($line=~m/href="([\w\d\.\/]+)"/){
my $pkg_url=$1;
$pkg_url=~s|\.\.\/\.\.|http://mirrors.ustc.edu.cn/CRAN|;
$response=$browser->get("$pkg_url");
$content=$response->{content};
$content=~m/href="(.*tar.gz)"/;
$down_link=$1;
$down_link=~s|\.\.\/\.\.\/\.\.|http://mirrors.ustc.edu.cn/CRAN|;
if($down_link=~m/\/([\w\d\._\-]+\.tar\.gz)$/){
$i++;
my $pkg_name=$1;
print "$i Downloading!!!\n";
system("wget -c $down_link -O $pkg_name");
}
}
}
~
use HTTP::Tiny;
use Data::Dumper;
my $contrib_url="http://mirrors.ustc.edu.cn/CRAN/web/packages/available_packages_by_name.html";
my $browser=HTTP::Tiny->new();
my $response=$browser->get("$contrib_url");
my $content=$response->{"content"};
my @lines=split/\n/,$content;
my $i=0;
foreach my $line(@lines){
if($line=~m/href="([\w\d\.\/]+)"/){
my $pkg_url=$1;
$pkg_url=~s|\.\.\/\.\.|http://mirrors.ustc.edu.cn/CRAN|;
$response=$browser->get("$pkg_url");
$content=$response->{content};
$content=~m/href="(.*tar.gz)"/;
$down_link=$1;
$down_link=~s|\.\.\/\.\.\/\.\.|http://mirrors.ustc.edu.cn/CRAN|;
if($down_link=~m/\/([\w\d\._\-]+\.tar\.gz)$/){
$i++;
my $pkg_name=$1;
print "$i Downloading!!!\n";
system("wget -c $down_link -O $pkg_name");
}
}
}
~
本文转自 tiger506 51CTO博客,原文链接:http://blog.51cto.com/tiger506/1608601,如需转载请自行联系原作者