Skip to content

Instantly share code, notes, and snippets.

@kinopyo
Created June 21, 2011 08:58
Show Gist options
  • Save kinopyo/1037492 to your computer and use it in GitHub Desktop.
Save kinopyo/1037492 to your computer and use it in GitHub Desktop.
nokogiri parse https url
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