Skip to content

Instantly share code, notes, and snippets.

@rockydd
Created July 28, 2010 09:09
Show Gist options
  • Save rockydd/493822 to your computer and use it in GitHub Desktop.
Save rockydd/493822 to your computer and use it in GitHub Desktop.
require 'net/http'
require 'rexml/document'
# Web search for "madonna"
url = 'http://api.search.yahoo.com/WebSearchService/V1/webSearch?appid=YahooDemo&query=madonna&results=2'
# get the XML data as a string
xml_data = Net::HTTP.get_response(URI.parse(url)).body
# extract event information
doc = REXML::Document.new(xml_data)
titles = []
links = []
doc.elements.each('ResultSet/Result/Title') do |ele|
titles << ele.text
end
doc.elements.each('ResultSet/Result/Url') do |ele|
links << ele.text
end
# print all events
titles.each_with_index do |title, idx|
print "#{title} => #{links[idx]}\n"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment