Created
May 13, 2017 08:37
-
-
Save hyuki0000/385a7750fa90ae135ec6de36254b115a to your computer and use it in GitHub Desktop.
mechanize-sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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 | |
# https://www.xmisao.com/2013/10/05/ruby-www-mechanize.html | |
# https://www.xmisao.com/2014/04/02/ruby-www-mechanize-2.html | |
# http://d.hatena.ne.jp/otn/20090509/p1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment