Skip to content

Instantly share code, notes, and snippets.

@deeeki
Created March 10, 2012 05:59
Show Gist options
  • Save deeeki/2010505 to your computer and use it in GitHub Desktop.
Save deeeki/2010505 to your computer and use it in GitHub Desktop.
tokyosharehouse_emptyrooms
# coding: utf-8
require 'mechanize'
SITE_URL = 'http://tokyosharehouse.com'
AREA_URL = "#{SITE_URL}/jpn/houses/area"
a = Mechanize.new
rows = [%w(name area status price line access cond comment url).join(',')]
catch(:break) do
a.get(AREA_URL)
while 1 do
a.page.search('.lineupRight').each do |elm|
throw :break if elm.at('.houseName > a > img')['alt'] == '満室'
cols = [
elm.at('.houseName > p').text.strip,
elm.search('dd')[0].text.strip,
elm.at('.houseName > a > img')['alt'],
elm.search('dd')[1].text.strip,
elm.search('dd')[2].text.strip,
elm.search('dd')[3].text.strip,
elm.search('dd')[4].text.strip,
elm.at('.txtLineup').text.strip,
SITE_URL + elm.at('.houseName > p > a')['href'],
]
rows << ('"' << cols.map{|c| c.to_s.gsub(/"/, '""')}.join('","') << '"')
end
a.page.link_with(:class => 'next').click
end
end
puts rows.join("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment