megas
megas

Reputation: 21791

How to get text from 'td' tags from 'table' tag on html page using Mechanize

How to get texts from 'td' tags from 'table' on html page by using Mechanize gem?

Upvotes: 0

Views: 1132

Answers (1)

Dru
Dru

Reputation: 9820

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

Upvotes: 2

Related Questions