From: Peter Szinek Date: 2006-12-13T22:58:34+09:00 Subject: Re: Hpricot html parsing Dhanasekaran Vivekanandhan wrote: > yes, I want the text of the first

because it > has an image. and reject if

has no image. > thanks, I see. Try this: =============================================== require 'rubygems' require 'hpricot' doc = Hpricot %q{

this is fun

NO FUN

fun again!

NO FUN AT ALL!

} paragraphs = doc/'p' good_elems = paragraphs.map.reject {|elem| ((elem/"img").empty?) } good_elems.each { |elem| puts elem.inner_text.strip } =============================================== output: ************ this is fun fun again! ************ You will need hpricot 0.4.84 because of inner_text - if you don't want to install it (I did not experience any difficulties, so I can recommend it) then you have to roll your own inner_text, but I guess this is not a big problem. Cheers, Peter