2015年 就職情報サイトから、企業名で検索して紹介ページURL を取得する。
require 'watir-webdriver'
file_path = 'where-to-save-file.txt'
f = File.new(file_path, 'w')
companies = %w(ハル研究所 任天堂 三菱 トヨタ)
b = Watir::Browser.new
companies.each do |query|
b.goto 'http://job.mynavi.jp/15/pc/toppage/displayTopPage/index'
b.text_field(name: 'srchWordCorp').set query
b.button(name: 'doSearchCorpName').click
f.puts b.h3s.first.a.href # saving first search result
end
b.close
require 'mechanize'
m = Mechanize.new {|agent|
agent.user_agent_alias = 'Mac Safari'
}
URL = 'http://job.rikunabi.com/2015/s/?freeword='
companies = %w(ハル研究所 任天堂 三菱 トヨタ)
companies.each do |param|
page = m.get(URL + param)
regex = /2015\/company\/top\/.*\//
uri = page.links_with(href: regex).first.uri.to_s # get first search result
prefix = 'http://job.rikunabi.com'
puts prefix + uri
end