# Hpricot and XPaths with indices

**URL:** <https://www.ruby-forum.com/t/hpricot-and-xpaths-with-indices/71262>\
**Category:** Ruby\
**Created:** [October 6, 2006, 3:11pm UTC](https://www.ruby-forum.com/t/hpricot-and-xpaths-with-indices/71262 "2006-10-06T15:11:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![splattael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@splattael](https://www.ruby-forum.com/u/splattael)\
**Post date:** [October 6, 2006, 3:11pm UTC](https://www.ruby-forum.com/t/hpricot-and-xpaths-with-indices/71262/1 "2006-10-06T15:11:48Z")

</div>

Hello,

I just started to use HPricot a few days ago (what a cool piece of  
software! 😉 so it is possible that I have just overlooked it but I did  
not find a way to evaluate XPaths with indices yet. Instead of a general  
XPath, e.g.:

(doc/‘//div/table/tr/td/img’)

I would like to lookup an indexed one:

(doc/‘//div[2]/table[3]/tr[2]/td[8]/img[2]’).

OK, I guess this is doable by ((doc/'//div)[2]./table)[3]… or  
something similar, but is this the only (and accepted) way?

TIA,  
Peter  
[http://www.rubyrailways.com](http://www.rubyrailways.com)

---

<div class="post-metadata">

**Author:** ![splattael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@splattael](https://www.ruby-forum.com/u/splattael)\
**Post date:** [October 7, 2006, 2:55am UTC](https://www.ruby-forum.com/t/hpricot-and-xpaths-with-indices/71262/2 "2006-10-07T02:55:42Z")

</div>

[http://code.whytheluckystiff.net/hpricot/wiki/SupportedXpathExpressions](http://code.whytheluckystiff.net/hpricot/wiki/SupportedXpathExpressions)

Yay rftdocs. Hpricot’s XPath syntax seems quite incomplete, either e.g.  
div:eq(0) will work or nothing will.

David V.

---

<div class="post-metadata">

**Author:** ![splattael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@splattael](https://www.ruby-forum.com/u/splattael)\
**Post date:** [October 8, 2006, 5:49am UTC](https://www.ruby-forum.com/t/hpricot-and-xpaths-with-indices/71262/3 "2006-10-08T05:49:28Z")

</div>

On Sat, Oct 07, 2006 at 09:53:51AM +0900, David V. wrote:

> [http://code.whytheluckystiff.net/hpricot/wiki/SupportedXpathExpressions](http://code.whytheluckystiff.net/hpricot/wiki/SupportedXpathExpressions)
> 
> Yay rftdocs. Hpricot’s XPath syntax seems quite incomplete, either e.g.  
> div:eq(0) will work or nothing will.

Very true. And there are plans to enhance:  
[http://code.whytheluckystiff.net/hpricot/roadmap](http://code.whytheluckystiff.net/hpricot/roadmap)

Unfortunately, I am six days late as of this day. That is frownworthy,  
I know.

\_why
