7

I am having problems with my Perl program. This program logs in to a specific web page and fills up the text area for the message and an input box for mobile numbers. Upon clicking the 'Send' button, the message will be sent to the specified number. I already got it to work for sending messages. But the problem is I can't make it work for receiving messages/replies. I'm using WWW::Mechanize module in Perl. Here is a part of my code (for receiving msgs):

$username = 'suezy';
$password = '123';
$url = 'http://..sample.cgi';

# ...

$mech->credentials($username, $password);  
$mech->get($url);

$mech->submit(); 

My problem is, the forms shows no names. There are two buttons in this form, but I can't select which button to click, since there are no name specified and the ids contains a space(e.g. form name='receive msg'..). I need to click on the second button, 'Receive'.

Question is, how will I be able to access the forms and buttons using mechanize module without using names?

4

4 回答 4

4

您可以将 form_number 参数传递给 submit_form 方法。

或者调用 form_number 方法来影响以后调用 click 或 field 使用哪个表单。

于 2010-02-14T09:12:41.403 回答
4

您是否尝试过使用HTTP 记录器
查看文档并尝试查看它是否为您提供了合理的结果。

于 2010-02-14T09:54:40.280 回答
3

看到您的表单上只有两个按钮,ysth 的建议应该很容易实现。

use strict;
use warnings;
use WWW::Mechanize;

my $username = "suezy";
my $password = "123";
my $url = 'http://.../sample.cgi';
my $mech = WWW::Mechanize->new();

$mech->get($url);
$mech->credentials($username,$password);

接着:

$mech->click_button({number => 1});       # if the 'Receive' button is 1

或者:

$mech->click_button({number => 2});       # if the 'Receive' button is 2

反复试验的情况足以让您弄清楚您正在单击哪个按钮。

编辑

我假设已经选择了相关表格。如果不:

$mech->form_number($formNumber);

$formNumber有问题的页面上的表格编号在哪里。

于 2010-02-14T10:03:01.213 回答
1

$mech->form_with_fields('username');

将选择包含名为 username 的字段的表单。hth

于 2010-05-12T08:55:21.463 回答