#!/usr/local/bin/ruby require 'open-uri' require "pp" require 'uri' #
¥160
#https://www.google.co.jp/search?site=&q=新宿~渋谷 電車 from = "渋谷" to = "新宿" url_before_escape = "https://www.google.co.jp/search?site=&q=#{from}~#{to} 電車" url = URI.escape(url_before_escape) #p url_escape pp url sio = OpenURI.open_uri(url) fares = [] min_fare = 0 sio.each_line do |l| if l =~ %r|tdu-total-fare| # i = l.slice(%r|
¥([,0-9]*)
|, 1) i = l#.slice(%r|
¥(160)
|, 1) fares << i end end pp fares #min_fare = fares.sort.shift #pp min_fare