2009-10-18 7 views

Répondre

1

Essayez

doc = Nokogiri::HTML(open(url)).xpath("//*") 
.xpath("//*[br and text()[string-length(normalize-space()) != 0]]") 
.wrap("<span></span>") 

puts doc 

Ce que votre XPath fait est qu'il va chercher les nœuds de texte non vides. Qui, par définition, ne contiennent aucun balisage. Par contre, mon XPath récupère tout nœud contenant au moins un <br> et au moins un nœud de texte non vide.

Questions connexes