Module: Wanfang

Defined in:
lib/module/wanfang.rb

Class Method Summary collapse

Class Method Details

.crawlObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 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) ⇒ Object



21
22
23
24
25
26
# File 'lib/module/wanfang.rb', line 21

def self.split(hash)
    hash.each do |k, v|
        hash[k] = v.split("")[1]
    end
    hash
end