From: Estanislau Trepat Date: 2011-02-16T00:46:59+09:00 Subject: Re: Ruby(and programming) beginners question regarding 'NoMethodError' while using Hpricot --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 = doc.search('td[text()="PE ratio"]') => # "PE ratio" }]> # get the targeted cell > cell = elements*.first.*next_sibling => {elem " 16.83" } # printout raw value > puts cell.to_plain_text 16.83 => nil Regards. -- Estanislau Trepat 2011/2/15 Sandeep Guria > Hi! > I am trying to build a web scraper which fetches Fundamental data for > listed companies from finance websites. > let me show an example. > > > " > PE ratio > 16.8314/02/11 > > EPS (Rs) > 10.59Mar, 10 > Sales (Rs crore) > 13,963.81Dec, 10 > Face Value (Rs) class="numericalColumn">10 > Net profit margin (%) > 17.72Mar, 10 > > Last dividend (%) class="numericalColumn">3018/01/11 > Return on average equity class="numericalColumn">13.69Mar, 10 > > " > 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 > `
': undefined method `next_sibling' for # "PE ratio" }]> (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--