Why can't WWW::Mechanize find the right form?

可紊 提交于 2020-01-25 05:39:26

问题


I'm using WWW::Mechanize to retrieve a form from a webpage:

#!/usr/bin/perl

use WWW::Mechanize;

my $mechanize = WWW::Mechanize->new();

$mechanize->proxy(['http', 'ftp'], 'http://proxy/');

$mechanize->get("http://www.temp.com/");

$mechanize->form_id('signin');

The website HTML has code as follows

<form action="https://www.temp.com/session" id="signin" method="post">

but I get the error

 There is no form with ID "signin" at SiteScraper.pl

What do I do?


回答1:


Without knowing exactly could be wrong, you might try to output whatever forms that WWW::Mechanize is able to find in the response by using:

use Data::Dumper;
print Dumper($mechanize->forms());

It should output all the forms and their respective attributes etc.

Double check that the form is in the dump, otherwise something is wrong. Then check that the form's ->{attr}->{id} is what you expect as well.

You can also try to select the form using another way, e.g. by name, and see if that helps.



来源:https://stackoverflow.com/questions/3708648/why-cant-wwwmechanize-find-the-right-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!