Hpricot 获取HTML文档中某个元素第一次出现的位置 2015/06/06 14145 require 'rubygems' require 'hpricot' require 'open-uri' doc = Hpricot(open('http://www.rubyinside.com/test.html')) puts doc.search("h1").first.inner_html list = doc.at("ul") list.search("li").each do |item| puts item.inner_html end