2013-02-18 101 views
-1

我已使用WWW::Mechanize登錄該網站。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."); 
+5

更好的複製/粘貼代碼,而不是顯示快照... – 2013-02-18 19:14:47

+0

添加它sputnick。 – StackedFlow 2013-02-18 23:31:26

+0

我不明白什麼「所以從這個我想然後閱讀是什麼,然後選擇正確的行動」的意​​思。我們需要更多細節。到「payments.php」是什麼意思? payments.php在哪裏? Mech所做的一切只是模擬瀏覽器操作,所以按照點擊或提交來描述它。 – 2013-02-18 23:51:16

回答

1

我想你需要

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

,但我不能幫你從那裏獲取信息,而不會看到頁面的HTML。

1

您需要解析結果HTML文件。我建議使用HTML :: TreeBuilder作爲:: XPath來這樣的任務:的

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

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