【发布时间】:2012-12-28 03:23:30
【问题描述】:
这是我的网页示例数据
<hr>
<h4>This is Second line</h4>
Some Text Here<br>
Some More Text Here<br>
<h4>This is First line</h4>
Mem Capacity : 130.65 MB<br>
Mem Used : 74.52 MB<br>
Mem Available : 56.13 MB<br>
Mem Used Percentage : 57<br>
我正在使用下面的代码来提取类似的东西
Mem Capacity : 130.65 MB
Mem Used : 74.52 MB
Mem Available : 56.13 MB
Mem Used Percentage : 57
代码如下:
#!/usr/bin/perl
use WWW::Mechanize;
$mech = WWW::Mechanize->new();
$url = 'some url';
$result = $mech->get( $url );
$content = $result->as_string();
print $content;
if($content =~ /Mem Capacity :([\d.]+)/)
{
$value = $1;
print "Memory Capacity $value MB n";
}
我没有得到任何输出。谁能告诉我哪里出错了?
【问题讨论】:
-
你应该
use strict; use warnings;。在这种情况下,如果您只有 HTML 来处理,我还建议使用 HTML 解析器而不是 WWW::Mechanize。 -
@squiguy 你能告诉我如何用 HTML 解析器实现相同的代码吗?
-
这显然是这个问题的延续:stackoverflow.com/questions/14051191/… 我的问题仍然是一样的:你如何定义你正在寻找的行?
标签: perl perl-module www-mechanize