2

我正在编写一个脚本来选择尺寸并将产品添加到购物车这里是 http://store.nike.com/us/en_us/pd/free-4-flyknit-running-shoe/pid-1064825 /pgid-1481072

use WWW::Mechanize::Firefox;
$mech = WWW::Mechanize::Firefox->new();

my $tconike = "http://store.nike.com/us/en_us/pd/free-4-flyknit-running-shoe/pid-1064825/pgid-1481072";

$mech->get($tconike);
print $mech->uri();
$mech->submit_form(
    form_number=> 2,
    fields => {
    skuAndSize => $shoesize,
    click => "ADD TO CART",
    }
);

但这是输出

Uncaught exception from user code:
        No form found to submit. at nikecartstandalone.pl line 25
 at C:/Users/Brett/Documents/brett/Perl/perl/site/lib/WWW/Mechanize/Firefox.pm l
ine 2162
        WWW::Mechanize::Firefox::signal_condition('WWW::Mechanize::Firefox=HASH(
0x2a54888)', 'No form found to submit.') called at C:/Users/Brett/Documents/bret
t/Perl/perl/site/lib/WWW/Mechanize/Firefox.pm line 3649
        WWW::Mechanize::Firefox::submit_form('WWW::Mechanize::Firefox=HASH(0x2a5
4888)', 'form_number', 2, 'fields', 'HASH(0x3501328)') called at nikecartstandal
one.pl line 25

任何人都知道我做错了什么,是因为我应该使用其他东西submit_form还是其他东西?

4

1 回答 1

0

由于错误表明它无法找到表单,因此请尝试使用with_fields提交表单,您可以在其中指定要提交的表单中的字段,这样更容易搜索和提交。

例如:$mech->form_with_fields('username'); 将选择包含名为 username 的字段的表单。

于 2014-05-09T08:41:32.947 回答