如何使用 Perl 的 WWW::Mechanize 访问没有名称或 ID 的表单?
我的 Perl 程序有问题。该程序登录到特定网页并填充消息的文本区域和手机号码的输入框。单击“发送”按钮后,消息将发送至指定号码。我已经让它可以用来发送消息了。但问题是我无法让它用于接收消息/回复。我在 Perl 中使用 WWW::Mechanize 模块。这是我的代码的一部分(用于接收消息):
$username = 'suezy';
$password = '123';
$url = 'http://..sample.cgi';
# ...
$mech->credentials($username, $password);
$mech->get($url);
$mech->submit();
我的问题是,表单没有显示名称。此表单中有两个按钮,但我无法选择要单击哪个按钮,因为没有指定名称并且 ids 包含空格(例如表单名称='接收消息'..) 。我需要单击第二个按钮“接收”。
问题是,我如何能够使用 mechanize 模块访问表单和按钮而不使用名称?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以将 form_number 参数传递给 Submit_form 方法。
或者调用form_number方法来影响以后调用click或field时使用哪个表单。
You can pass a form_number argument to the submit_form method.
Or call the form_number method to affect which form is used by later calls to click or field.
您是否尝试过使用 HTTP 记录器?
查看文档并尝试一下,看看它是否为您提供合理的结果。
Have you tried to use HTTP Recorder?
Have a look at the documentation and try it to see if it gives a reasonable result for you.
看到您的表单上只有两个按钮,ysth 的建议应该很容易实现。
然后:
或者:
反复试验的情况足以让您弄清楚您正在单击哪个按钮。
编辑
我假设相关表单已被选择。如果不是:
其中
$formNumber
是相关页面上的表单编号。Seeing that there are only two buttons on your form, ysth's suggestion should be easy to implement.
And then:
Or:
A case of trial-and-error is more than adequate for you to figure out which button you're clicking.
EDIT
I'm assuming that the relevant form has already been selected. If not:
where
$formNumber
is the form number on the page in question.$mech->form_with_fields('username');
将选择包含名为 username 的字段的表单。
哈
$mech->form_with_fields('username');
will select the form that contain a field named username.
hth