On Mar 17, 10:03 am, Todd Benson <caduce... / gmail.com> wrote:
> On Sun, Mar 16, 2008 at 12:30 PM, Junkone <junko... / gmail.com> wrote:
> > hello
> >  I am trying to grab the table that has a html comment in it. for eg
>
> >  <TABLE cellSpacing=1 width="80%" align=center border=0><!--
> >  startingtable -->
>
> >  how can i do using search functionality in hpricot.
>
> >  appreciate any help
>
> 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 = <TABLE cellspacing=1 width= 80% align=center border=0><!--
> startingtable -->
> doc = Hpricot(str)
> p doc.search("table").inner_html
>
> =>"<!-- startingtable -->\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('<table><!-- startingtable --></table><div><!-- some div --
></div>')
table = (h/'table > comment()')[0].parent