使用WWW :: Mechanize - Perl将产品添加到购物车

时间:2014-05-08 22:31:11

标签: perl mechanize www-mechanize www-mechanize-firefox

我正在编写一个选择尺寸的脚本,并将产品添加到购物车中,就在这里 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

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

1 个答案:

答案 0 :(得分:0)

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

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

相关问题