From: Sylvain Tenier Date: 2006-12-19T16:31:00+09:00 Subject: Re: find all possible container nodes of a given text well I think I solved it #!/usr/bin/ruby require 'hpricot' html = <
harr is a dogfuu is a catjii is adog
EOS doc = Hpricot(html) result=[] doc.traverse_text do |text| text_out = text.to_s.strip if text_out =~ /dog/ result << text.parent.xpath end end thanks anyway Sylvain Selon Sylvain Tenier : > hi, > I've been using ruby for a few weeks and been messing with DOM-like > programming > using hpricot. > I'm looking for an efficient (rubyiish) way to find the set of Node Elements > that have a text_element child containing a given string > > for instance given the html code > >
harr is a dogfuu is a catjii is > a > dog
> > I would like to set this query > > getNodesContaining("dog") > > that would return an Array with the xpath of the first and third td (since > they > contain the text dog) > > thanks in advance > > Sylvain > > -- > Rien ne peut jamais marcher si l'on songe � tout ce qu'il faut pour que �a > marche. > -- Daniel Pennac >