module Wanfang

Public Class Methods

crawl() click to toggle source
# File lib/module/wanfang.rb, line 2
def Wanfang.crawl
    hash = {}
    url = "http://www.wanfang.gov.tw/W402008web_new/epd_query.asp"
    begin
        page = Nokogiri::HTML(open(url))
        hash[:hospital] = "wanfang"
        hash[:to_119]        = page.css("body table:nth-child(1) tr:nth-child(9) td:nth-child(1) table tr td ul:nth-child(3) li:nth-child(1)").text.strip
        hash[:wait_see]      = page.css("body table:nth-child(1) tr:nth-child(9) td:nth-child(1) table tr td ul:nth-child(3) li:nth-child(2)").text.gsub("人", "").strip
        hash[:wait_push_bed] = page.css("body table:nth-child(1) tr:nth-child(9) td:nth-child(1) table tr td ul:nth-child(3) li:nth-child(3)").text.gsub("人", "").strip
        hash[:wait_bed]      = page.css("body table:nth-child(1) tr:nth-child(9) td:nth-child(1) table tr td ul:nth-child(3) li:nth-child(4)").text.gsub("人", "").strip
        hash[:wait_cure_bed] = page.css("body table:nth-child(1) tr:nth-child(9) td:nth-child(1) table tr td ul:nth-child(3) li:nth-child(5)").text.gsub("人", "").strip
        hash = self.split(hash)
    rescue Exception => e
        p e.message
        return nil
    end
    return hash
end
split(hash) click to toggle source
# File lib/module/wanfang.rb, line 21
def self.split(hash)
    hash.each do |k, v|
        hash[k] = v.split(":")[1]
    end
    hash
end