문제

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?

도움이 되었습니까?

해결책

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top