How to GET a URL with User-Agent and timeout through some Proxy in Ruby?
How do I get a URL if I need to get it through some proxy , it has to have a timeout of max n. seconds, and a User-Agent ? require 'nokogiri' require 'net/http' require 'rexml/document' def get_with_max_wait(param, proxy, timeout) url = "http://example.com/?p=#{param}" uri = URI.parse(url) proxy_uri = URI.parse(proxy) http = Net::HTTP.new(uri.host, 80, proxy_uri.host, proxy_uri.port) http.open_timeout = timeout http.read_timeout = timeout response = http.get(url) doc = Nokogiri.parse(response.body) doc.css(".css .goes .here")[0].content.strip end The code above gets a URL through a proxy with