Skip to content

Instantly share code, notes, and snippets.

/ruby.rb Secret

Created May 27, 2016 11:10
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 anonymous/d130ebd2c00e32608d9e98eb4881cd59 to your computer and use it in GitHub Desktop.
Save anonymous/d130ebd2c00e32608d9e98eb4881cd59 to your computer and use it in GitHub Desktop.
require "net/http"
require "uri"
require 'nokogiri'
uri = URI.parse("http://limepepper.co.uk/test.xml")
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new(uri.request_uri)
response = http.request(request)
doc = Nokogiri::XML(response.body)
links = doc.css("a")
puts links.length
links.each do |link|
puts link.text # => Click here
puts link["href"] # => http://www.google.com
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment