0

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?

Roaring Stones
  • 1,054
  • 7
  • 22

1 Answers1

1

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
Fabio
  • 18,856
  • 9
  • 82
  • 114