Pregunta

I have a problem requesting website with httparty gem: anti-bot system responds me with some boring stuff ) does httparty have any standart methods to alter request headers(I mean UserAgent, etc.)? or can it be done in other way?

¿Fue útil?

Solución

I solved this issue some time ago by using the mechanize gem which has user agent and cookies support built in.

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
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top