【问题标题】:How to get text from 'td' tags from 'table' tag on html page using Mechanize如何使用 Mechanize 从 html 页面上的“table”标签中的“td”标签获取文本 【发布时间】:2012-04-03 19:47:28 【问题描述】: 如何使用 Mechanize gem 从 html 页面上的 'table' 中获取 'td' 标签中的文本? 【问题讨论】: Ruby Nokogiri Parsing HTML table II 的可能重复项 另见:stackoverflow.com/a/8233949/128421 标签: ruby mechanize 【解决方案1】: 我几乎总是将 mechanize 与 nokogiri 一起使用。这个guide 帮助我开始了。 这样的东西应该可以工作(未经测试): 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 更多关于 nokogiri 的信息here 【讨论】: 谢谢,Mechanize 已经使用 nokogiri,所以使用 Mechanize 的 xpath 查找会更正确 谢谢,帮我省了一些钱。过去,我总是单独要求它。