【发布时间】:2014-05-22 17:31:03
【问题描述】:
我是 HTML::Parser 的 Perl 新手。
我正在尝试解析网页,然后搜索特定字符串,例如 pass 或 fail。我该怎么办呢。
由于框架问题,我必须使用 HTML::Parser 基础库而不是其他模块。
代码片段
#!/usr/bin/perl
use strict;
# define the subclass
package IdentityParse;
package HTMLStrip;
use base "HTML::Parser";
sub text {
my ($self, $text) = @_;
# just print out the original text
print $text;
}
sub comment {
my ($self, $comment) = @_;
# print out original text with comment marker
#print "hey hey";
}
sub end {
my ($self, $tag, $origtext) = @_;
# print out original text
#print $origtext;
}
#my $p = new IdentityParse;
my $p = new HTMLStrip;
my @file = $p->parse_file("testcase1.html");
if ($p->parse_file("testcase1.html") =~ "PASS") {
print " The test passed \n";
}
else {
print "\nthe test failed \n";
}
【问题讨论】:
标签: perl html-parsing