--000e0ce0ad1effa103049c5412a8
Content-Type: text/plain; charset=UTF-8

Hi Sandeep.

The #search method returns an Hpricot::Elements object, which is somewaht
similar to an array. You should call #next_sibling on any of the elements
inside that collection, which, in fact, are Hpricot::Elem objects. For
instance:

# perform search
> elements  oc.search('td[text()E ratio"]')
#<Hpricot::Elements[{elem <td> "PE ratio" </td>}]>

# get the targeted cell
> cell  lements*.first.*next_sibling
{elem <td classumericalColumn"> "           16.83" </td>}

# printout raw value
> puts cell.to_plain_text
16.83
nil

Regards.

--
Estanislau Trepat


2011/2/15 Sandeep Guria <sndpgr / hotmail.com>

> Hi!
> I am trying to build a web scraper which fetches Fundamental data for
> listed companies from finance websites.
> let me show an example.
>
>
> "<tbody>
>          <tr><td>PE ratio</td><td classumericalColumn">
> 16.83</td><td>14/02/11</td></tr>
>
>          <tr><td>EPS (Rs)</td><td classumericalColumn">
> 10.59</td><td>Mar, 10</td></tr>
>          <tr><td>Sales (Rs crore)</td><td classumericalColumn">
> 13,963.81</td><td>Dec, 10</td></tr>
>          <tr><td>Face Value (Rs)</td><td
> classumericalColumn">10</td><td> </td></tr>
>          <tr><td>Net profit margin (%)</td><td classumericalColumn">
> 17.72</td><td>Mar, 10</td></tr>
>
>          <tr><td>Last dividend (%)</td><td
> classumericalColumn">30</td><td>18/01/11</td></tr>
>          <tr><td>Return on average equity</td><td
> classumericalColumn">13.69</td><td>Mar, 10</td></tr>
>        </tbody>
> "
> I want to the data '16.83' from the above html , so what I do is
> I parse the HTML file and save it into doc.
> I search doc for inner text 'PE ratio'
> And then I chose the next element using next_sibling.
> But I am getting an error
> 'C:\Users\Administrator\Documents>ruby scraper.rb scraper.rb:9:in
> `<main>': undefined method `next_sibling' for #<Hpricot::Elements[{elem
> <td> "PE ratio" </td>}]> (NoMethodError)'
>
> I'll be grateful for any suggestions .
> Sorry about the formatting of the HTML Text!
>
> Attachments:
> http://www.ruby-forum.com/attachment/5911/scraper.rb
>
>
> --
> Posted via http://www.ruby-forum.com/.
>
>

--000e0ce0ad1effa103049c5412a8--