2011-09-02 294 views
0

我想通过Perl模块WWW :: Mechanize搜索yellowpages.com。WWW :: Mechanize和yellowpages.com

$mech->get("http://www.yellowpages.com"); 
$mech->form_name("standard-searchform"); 
$mech->field("search-terms, "schneider"); 
$mech->field("search-location", "CA"); 
$mech->submit(); 

我也试过$ mech-> submit_form(...)与按钮值/类型,但我得到了以下信息所有的时间:

Error POSTing http://www.yellowpages.com/real_deals: Internal Server Error at /usr/lib/cgi-bin/index.pl line 39 

39号线是

$mech->submit(); 

是yp.com转发机械化到该网站?我怎样才能避免这种情况?

+0

我已回滚到修订1,因为这个问题没有意义,否则。 (别担心,我们都会犯错:)) – Zaid

回答

1

首先,您在搜索条件后错过了"。查看黄页的源代码,没有名称为“standard-searchform”的表单。该表单带有一个ID“searchform-form”。这样的例子应该工作:

my $mech = WWW::Mechanize->new; 

$mech->get("http://www.yellowpages.com"); 
$mech->form_id("searchform-form"); 
$mech->field("search-terms", "schneider"); 
$mech->field("search-location", "CA"); 
$mech->submit(); 

编辑:

也是搜索项和搜索位置是输入的ID,其中WWW的文件::机械化说:

给定一个字段的名称,将其值设置为指定的值

这意味着您应该将它们更改为:search_terms和geo_location_terms。

+0

谢谢,我在我的文章中纠正了它。我也尝试过** searchform-form **,并得到相同的错误。代码是否适合你? – manuel

+0

这是表单的ID,所以它应该是form_id而不是form_name –

+0

非常感谢,我将它改为** form_id **,并且还将ID更改为名称。现在工作! – manuel

相关问题