2012-05-24 54 views
0

我有一個問題,請求網站與httparty寶石:防機器人系統響應我一些無聊的東西) 確實httparty有任何標準的方法來更改請求標頭(我的意思是UserAgent等)? 還是可以用其他方式完成?問題與反請求網站與httparty

回答

1

我使用mechanize寶石具有用戶代理和cookie支持內置的解決了這個問題,前一段時間

Quick example

require 'rubygems' 
require 'mechanize' 

a = Mechanize.new { |agent| 
    agent.user_agent_alias = 'Mac Safari' 
} 

a.get('http://google.com/') do |page| 
    search_result = page.form_with(:name => 'f') do |search| 
    search.q = 'Hello world' 
    end.submit 

    search_result.links.each do |link| 
    puts link.text 
    end 
end 
+0

非常感謝你!它完美的作品! –