我知道这可能是一个愚蠢的问题。我正在尝试使用这个 xml 解析器
http://nokogiri.rubyforge.org/nokogiri/Nokogiri.html
我把下面的代码放在了一个bringRSS方法(?)的控制器中,它在IRB中运行良好。但是我如何获取puts link.content的值到我的视图中
def bringRSS
require 'nokogiri'
require 'open-uri'
# Get a Nokogiri::HTML:Document for the page we’re interested in...
doc = Nokogiri::HTML(open('http://www.google.com/search?q=tenderlove'))
# Do funky things with it using Nokogiri::XML::Node methods...
####
# Search for nodes by css
doc.css('h3.r a.l').each do |link|
puts link.content
end
####
# Search for nodes by xpath
doc.xpath('//h3/a[@class="l"]').each do |link|
puts link.content
end
####
# Or mix and match.
doc.search('h3.r a.l', '//h3/a[@class="l"]').each do |link|
puts link.content
end
end