ruby - How do I grab this value from Nokogiri? -
say have:
<div class="amt" id="displayfare-1_69-61-0" style=""> <div class="per">per person</div> <div class="per" id="showtotalsubindex-1_69-61-0" style="">total $334</div> $293 </div> i want grab $334. have "total $" id showtotalsubindex... dynamic can't use that.
you can use nokogiri xpath expression iterate on div nodes , scan string 'total $' prefix this
require 'rubygems' require 'nokogiri' doc = nokogiri::xml.parse( open( "test.xml" )) doc.xpath("//div/text()").each{ |t| tmp = t.to_str.strip puts tmp[7..-1] if tmp.index('total $') == 0 }
Comments
Post a Comment