Skip to content

Instantly share code, notes, and snippets.

@deeeki
Created March 9, 2012 18:57
Show Gist options
  • Save deeeki/2008059 to your computer and use it in GitHub Desktop.
Save deeeki/2008059 to your computer and use it in GitHub Desktop.
hituji_tokyo_emptyrooms
require 'mechanize'
SITE_URL = 'http://www.hituji.jp'
INFO_URL = "#{SITE_URL}/comret/info"
a = Mechanize.new
links = a.get(INFO_URL).search('.searchAreaElement').at('td').search('a').map do |city|
city['href']
end
rows = [%w(name type low high status line owner cond comment id url).join(',')]
links.each do |l|
a.get(l).search('.propertyList').search('h3, .propertySummary').each do |elm|
break if elm.name == 'h3'
/(?<type>[^\d]+)¥(?<low>[\d]+) \- (?<high>[\d]+).*/ =~ elm.at('.emptyInfo').child.text.strip
cols = [
elm.at('.houseName > a').text.strip,
type,
low,
high,
elm.at('.emptyStatusLabel > a').text.strip,
elm.at('.lineInfo').child.text.strip,
elm.at('.ownerName > a').text.strip,
elm.at('.ownerName').next.text.strip,
elm.at('.comment').text.strip,
elm.at('.propertyId').text.strip,
SITE_URL + elm.at('.houseName > a')['href'],
]
rows << ('"' << cols.map{|c| c.to_s.gsub(/"/, '""')}.join('","') << '"')
end
end
puts rows.join("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment