我不是 Perl 专家,但我编写了一个 Perl 脚本来解析 HTML 页面并按所有href
标签进行过滤:
输出如下图所示:
href="?Name">Name</a>
href="?Desc">Hourly Details</a>
href="/24x7/2012/11-November/">Data
href="./00:00:00/">00:00:00/</a>
href="./01:00:00/">01:00:00/</a>
href="./02:00:00/">02:00:00/</a>
href="./03:00:00/">03:00:00/</a>
href="./04:00:00/">04:00:00/</a>
href="./05:00:00/">05:00:00/</a>
href="./06:00:00/">06:00:00/</a>
href="./07:00:00/">07:00:00/</a>
href="./08:00:00/">08:00:00/</a>
href="./09:00:00/">09:00:00/</a>
href="./10:00:00/">10:00:00/</a>
href="./11:00:00/">11:00:00/</a>
href="./12:00:00/">12:00:00/</a>
href="./13:00:00/">13:00:00/</a>
href="./14:00:00/">14:00:00/</a>
href="./15:00:00/">15:00:00/</a>
href="./16:00:00/">16:00:00/</a>
href="./17:00:00/">17:00:00/</a>
href="./18:00:00/">18:00:00/</a>
href="./19:00:00/">19:00:00/</a>
href="./20:00:00/">20:00:00/</a>
href="./21:00:00/">21:00:00/</a>
href="./22:00:00/">22:00:00/</a>
href="./23:00:00/">23:00:00/</a>
现在我想从“00:00:00”到“23:00:00”提取href标签中的值,同时排除其他值。结果值将被添加到具有 URL 的字符串中:
http://x.download.com/00:00:00
------URL------------/..href../
..............................
http://x.download.com/23:00:00
但是,通过尝试以下代码:
foreach (@tag) {
if (m/href/) {
if ($_ =~ /"\/24/ && $_ =~ /"\/[0-9]/) {
my $href = $_;
my $start = index($href, "\"");
my $end = rindex($href, "\"");
my $link = substr($href, $start + 1, $end - $start - 1);
print "Follow: " . $url . $link . "\n";
}
}
}
印刷:
Follow: http://x.download.com/24x7/2012/11-November/
我的正则表达式应该是什么才能实现所需的目标?