2017-05-13   web   ruby   mechanize   nokogiri 

Ruby Mechanizeの小さなサンプル

Ruby Mechanizeの小さなサンプル

#! /usr/bin/env ruby

require 'mechanize'
require 'nokogiri'

agent = Mechanize.new
page1 = agent.get('https://www.google.co.jp')
form = page1.forms[0]
form.q = 'Sports'
page2 = agent.submit(form)
page2.links.each do |link|
  puts "[#{link.text}](#{link.href})"
end

参照

 2017-05-13   web   ruby   mechanize   nokogiri