# Hpricot search help

**URL:** <https://www.ruby-forum.com/t/hpricot-search-help/132085>\
**Category:** Ruby\
**Created:** [March 16, 2008, 6:30pm UTC](https://www.ruby-forum.com/t/hpricot-search-help/132085 "2008-03-16T18:30:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [March 16, 2008, 6:30pm UTC](https://www.ruby-forum.com/t/hpricot-search-help/132085/1 "2008-03-16T18:30:47Z")

</div>

hello  
I am trying to grab the table that has a html comment in it. for eg

how can i do using search functionality in hpricot.

appreciate any help

---

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [March 17, 2008, 12:12am UTC](https://www.ruby-forum.com/t/hpricot-search-help/132085/2 "2008-03-17T00:12:25Z")

</div>

On Sun, Mar 16, 2008 at 12:30 PM, Junkone [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 

There’s probably a better way, but without looking at the docs I would  
probably find my table and then maybe #inner\_html followed with a  
regexp.

For example…

require “hpricot”  
str =

  
doc = Hpricot(str)  
p doc.search(“table”).inner\_html

=\>“\n”

It’s interesting to note that hpricot picked it out even though that  
string is really malformed html.

Todd

---

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [March 17, 2008, 4:40am UTC](https://www.ruby-forum.com/t/hpricot-search-help/132085/3 "2008-03-17T04:40:42Z")

</div>

On Mar 17, 10:03 am, Todd B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> p doc.search(“table”).inner\_html
> 
> =\>“\n”
> 
> It’s interesting to note that hpricot picked it out even though that  
> string is really malformed html.
> 
> Todd

I think that this will do it:

h = Hpricot('

\<!-- some div –

> 

')

table = (h/‘table \> comment()’)[0].parent
