0

我曾经WWW::Mechanize登录到该网站。

现在我们已经登录,我想让WWW::Mechanize脚本转到payments.php然后找到活动用户订阅(例如 VIP 访问)(类:)<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.");
4

2 回答 2

1

我想你需要

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

但我无法帮助您从那里获取信息,而无需查看页面的 HTML。

于 2013-02-19T04:04:53.707 回答
1

您需要解析结果 HTML 文件。我建议将 HTML::TreeBuilder::XPath 用于此类任务:

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

my ($description) = $tree->findvalues('//p[ @class = "description" ]');
于 2013-02-19T04:11:30.370 回答