problems with a anti-robot system requesting site with httparty
-
10-06-2021 - |
Вопрос
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.
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
Не связан с StackOverflow