Skip to content

Instantly share code, notes, and snippets.

@thomd
Forked from kinopyo/nokogiri_https.rb
Created May 19, 2013 10:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomd/5607307 to your computer and use it in GitHub Desktop.
Save thomd/5607307 to your computer and use it in GitHub Desktop.
require 'net/https'
require 'nokogiri'
url = "https://example.com"
url = URI.parse( url )
http = Net::HTTP.new( url.host, url.port )
http.use_ssl = true if url.port == 443
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if url.port == 443
path = url.path
path += "?" + url.query unless url.query.nil?
res, data = http.get( path )
case res
when Net::HTTPSuccess, Net::HTTPRedirection
# parse link
doc = Nokogiri::HTML(data)
# do what you want ...
else
return "failed" + res.to_s
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment