# How to revise the programm to analyze web?

**URL:** <https://www.ruby-forum.com/t/how-to-revise-the-programm-to-analyze-web/185746>\
**Category:** Ruby\
**Created:** [March 25, 2010, 3:44pm UTC](https://www.ruby-forum.com/t/how-to-revise-the-programm-to-analyze-web/185746 "2010-03-25T15:44:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![luofeiyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@luofeiyu](https://www.ruby-forum.com/u/luofeiyu)\
**Post date:** [March 25, 2010, 3:44pm UTC](https://www.ruby-forum.com/t/how-to-revise-the-programm-to-analyze-web/185746/1 "2010-03-25T15:44:03Z")

</div>

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](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](http://quotes.money.163.com/corp/1034/code=601398.html)

---

<div class="post-metadata">

**Author:** ![luofeiyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@luofeiyu](https://www.ruby-forum.com/u/luofeiyu)\
**Post date:** [March 25, 2010, 4:43pm UTC](https://www.ruby-forum.com/t/how-to-revise-the-programm-to-analyze-web/185746/2 "2010-03-25T16:43:51Z")

</div>

On Thu, Mar 25, 2010 at 3:44 PM, Pen T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> puts ‘’  
> 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](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.
