Skip to content

Hpricot XPath Search

i5m edited this page Sep 13, 2010 · 2 revisions

(Part of An Hpricot Showcase.)

Before starting this section, you are encouraged to read Hpricot CSS Search. The CSS selectors are almost always easier to write and cleaner to combine. In addition, XPath support is pretty limited at present.

Using XPath Expressions

When calling the search or the slash / methods, you may use XPath expressions as the search string.

 doc = Hpricot(URI.parse("http://we-make-money-not-art.com/").read)
 (doc/'//div/img')
   #=> Elements[...]

For a complete list of expressions, see Supported XPath Expressions.

Return to An Hpricot Showcase.

Clone this wiki locally