Advertisement
Guest User

Untitled

a guest
May 27th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.43 KB | None | 0 0
  1.  
  2.  
  3. require "net/http"
  4. require "uri"
  5. require 'nokogiri'
  6.  
  7. uri = URI.parse("http://limepepper.co.uk/test.xml")
  8.  
  9.  
  10. http = Net::HTTP.new(uri.host, uri.port)
  11. request = Net::HTTP::Get.new(uri.request_uri)
  12.  
  13. response = http.request(request)
  14.  
  15. doc = Nokogiri::XML(response.body)
  16.  
  17. links = doc.css("a")
  18.  
  19. puts links.length
  20.  
  21. links.each do |link|
  22.  
  23. puts link.text   # => Click here
  24. puts link["href"] # => http://www.google.com
  25.  
  26. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement