2010-11-24 28 views

答えて

2

Mechanizeは、HTMLを解析するためにnokogiriを使用しています。そのため、そこでドキュメントを調べる必要があります。すなわち、xpathの方法を見てください。

require 'open-uri' 
require 'nokogiri' 
doc = Nokogiri::HTML(open('http://stackoverflow.com/questions/4265745/how-to-get-all-text-inside-td-tags-from-table-tag-on-html-page-using-mechaniz')) 
table = doc.xpath('//table').first # getting the first table on the page 
table.xpath('tr/td').count # getting all the td nodes right below table/tr and counting them 
#=> 4 
:ここ

は、現在のページを解析し、例を示します
関連する問題