WWW :: Mechanize从页面获取内容

时间:2013-02-18 18:45:01

标签: perl ubuntu vbulletin

我已使用WWW::Mechanize登录该网站。

现在我们已登录,我想让WWW::Mechanize脚本转到payments.php,然后找到活动用户订阅(例如VIP Access)(类:<p class="description">)。

从此我想知道那是什么,然后选择正确的动作。例如,如果用户打包状态为VIP Small,则打印PKG: VIP Small,如果用户打包状态VIP Full,则打印PKG: VIP Full

有谁知道这样做的方法?到目前为止使用的代码(在我的Ubuntu虚拟机中编码):

#!/usr/bin/perl

use WWW::Mechanize;

my $forum = "http://localhost/forums/forum.php";

print "Username\r\n";
my $username = <>;
chomp($username);

print "Password\r\n";
my $password = <>;

# do login
my $mech = WWW::Mechanize->new(agentcheck => 1, agent => 'Perl WWW::Mechanize');
$mech->get($forum);
$mech->submit_form(form_number => 1, fields => { vb_login_username => $username, vb_login_password = $password });

print "this far";
$mech->follow_link(text => "Click here if your browser does not automatically redirect you.");

2 个答案:

答案 0 :(得分:1)

我认为你需要

$mech->get('http://localhost/forums/payments.php');

但如果没有看到页面的HTML,我无法帮助您从中获取信息。

答案 1 :(得分:1)

您需要解析结果HTML文件。我建议使用HTML :: TreeBuilder :: XPath来完成这些任务:

my $tree = HTML::TreeBuilder::XPath->new_from_content( $mech->content() );

my ($description) = $tree->findvalues('//p[ @class = "description" ]');