如何使用 Mechanize gem 从 html 页面上的“table”中获取“td”标签中的文本?
问问题
1115 次
1 回答
2
I almost always use mechanize with nokogiri. This guide helped me get started.
Something like this should work (Untested):
require 'mechanize'
require 'nokogiri'
agent = Mechanize.new
page = agent.get("http://www.google.com/")
doc = Nokogiri::HTML(page.body, "UTF-8")
doc.xpath('//td').each do |node|
puts node.text
end
More information on nokogiri here
于 2012-04-03T21:28:09.830 回答