From: "Jesús Gabriel y Galán" Date: 2010-03-26T00:43:27+09:00 Subject: Re: how to revise the programm to analyze web? On Thu, Mar 25, 2010 at 3:44 PM, Pen Ttt wrote: > the following programme  can  run successfully,i can get a table > require 'hpricot' > require 'open-uri' > doc = Hpricot(open('http://webbbs.gamer.com.tw/board.php?brd=Chat&p=1')) > tab = (doc/'table[@class="ssize"]') > (tab/'tr').each_with_index do |line,index| > next if (index + 1) %2 == 0 > (line/'td').each do |data| > print data.inner_text.gsub("\n", '') + ' ' > end > puts '' > end > > when i change an other web (there is a table in it too) > i revise the programme > require 'hpricot' > require 'open-uri' > doc = > Hpricot(open('http://quotes.money.163.com/corp/1034/code=601398.html')) > tab = (doc/'table[@class="ssize"]') > (tab/'tr').each_with_index do |line,index| > next if (index + 1) %2 == 0 > (line/'td').each do |data| > print data.inner_text.gsub("\n", '') + ' ' > end > puts '' > end > > now , i can get nothing,how to revise it to get the table ? > please open it with your brower,then you can see the table ,what i want > to do is to get the data of the table , to analyse. > http://quotes.money.163.com/corp/1034/code=601398.html You have to look at the structure of the page, and come up with an xpath that will get you to the table you want, then write it instead of 'table[@class="ssize"]', because there's no table with that class in that page. I think that there might be some firefox addons that can produce a XPath for an element, but I can't remember. Firebug gives you one XPath but it's the "canonical" one, maybe you could simplify it, if you know it's the only table with a class, for example. Also be careful that maybe in this page, the internal structure of the table is different. In fact, if you check with Firebug you will see that the first column is a table and the second column is a div with more internal tables for each column. So you have to work a little bit more to extract the data from each cell. Jesus.