您可以使用XPathtext()选择器执行此操作。
require 'hpricot'require 'open-uri'doc = open("http://stackoverflow.com/") { |f| Hpricot(f) }text = (doc/"//*/text()") # array of text valuesputs text.join("n")然而,这是相当昂贵的操作。可能会有更好的解决方案。

您可以使用XPathtext()选择器执行此操作。
require 'hpricot'require 'open-uri'doc = open("http://stackoverflow.com/") { |f| Hpricot(f) }text = (doc/"//*/text()") # array of text valuesputs text.join("n")然而,这是相当昂贵的操作。可能会有更好的解决方案。