2011-09-02 52 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

相關問題