你能试试这个
require 'rubygems'
require 'net/http'
require 'rexml/document'
# Web search for
url = 'http://api.eventful.com/rest/events/search?app_key=PbFVZfjTXJQWrnJp&location=London&date=Today'
# 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)
doc.elements.each('search/events/event/title') do |ele|
titles = ele.text
p titles
end
输出:
C:\Users\vinothini\Desktop>ruby sample_nokogiri.rb
"The Ladykillers"
"The 39 Steps"
"Wotever Sex 6 August"
"Phoenix Fringe"
"The Lion King"
"One Man, Two Guvnors"
"Tutorfair event 6th Aug"
"Thriller - Live"
"The Color Purple"
"Summer School Mid-Term Party"
我是否正确理解了您的要求?