本帖最后由 523066680 于 2014-12-21 11:40 编辑
年初的脚本了,送给有下载收藏癖的人们,代码保存为UTF-8文本格式。
链接比较多没有写成Perl LWP 下载的,建议用迅雷批量。
所有链接放二楼- =info
- Code by: ViANG/523066680
- E-Mail : 523066680@163.com
- Date : 2014-01
- =cut
-
- use Encode;
- use LWP::Simple;
- use utf8;
- my $main="http://windows.microsoft.com";
- my $themepage="http://windows.microsoft.com/zh-cn/windows/themes";
-
- binmode(STDOUT,':encoding(gbk)');
- binmode(STDERR,':encoding(gbk)');
-
- my @all;
- my $title;
- @all=getpage($themepage,"themes.htm");
- $spec="最新主题";
- foreach (@all) {
- if ($_=~/${spec}/) {
- $title=$_;
- }
- }
- if (not defined $title) {
- print "\n无法找到和主题类目有关的信息。请检查信息来源\n";
- exit();
- }
-
- my @items=split('a href',$title);
- shift @items;
- my (@c_name,@link);
- my $i=0;
- foreach (@items) {
- $_=~/="(.*)" class.*title="(.*)" data/;
- $c_name[$i]=$2;
- $link[$i++]=$main . $1;
- }
-
- # 获取标题直到 "全景(双显示器)" 为止
- my $endmark="全景(双显示器)";
- my $sum;
- open ALLURL,">","linkofall.txt";
- FO: foreach (0..($i-1)) {
- @all=getpage($link[$_], $c_name[$_].".txt");
- print ALLURL encode("utf-8","# $c_name[$_]:\n");
- foreach my $code (@all) {
- if ($code=~/download.*\..*themepack/) {
- $sum=analyse($code);
- }
- }
- print ALLURL encode("utf-8","# 共计 $sum 个链接\n\n");
- last FO if ($c_name[$_] eq $endmark);
- }
- close ALLURL;
- print "\nOVER";
- <STDIN>;
- exit();
-
- sub getpage {
- my ($link, $name)=($_[0],$_[1]);
- $name=encode('gb2312',$name);
- if ( not -e $name ) {
- print "file not exist, downloading";
- getstore($link,$name) or die "$!";
- }
- open READ,"<:utf8",$name or die "can not open file, $!";
- my @all=<READ>;
- close READ;
- return @all;
- }
-
- sub analyse {
- my @all=split(">下载<",$_[0]);
- my $sum=0;
- foreach (@all) {
- if (/"(http:\/\/download.*\..*themepack)"$/) {
- $sum++;
- print ALLURL $1,"\n";
- }
- }
- return $sum;
- }
复制代码
|