Module: Chimei

Defined in:
lib/module/chimei.rb

Overview

奇美醫院

Class Method Summary collapse

Class Method Details

.crawlObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/module/chimei.rb', line 3

def Chimei.crawl
    hash = {}
    url = "http://www.chimei.org.tw/%E6%80%A5%E8%A8%BA%E5%8D%B3%E6%99%82%E8%A8%8A%E6%81%AF/main.aspx?ihosp=10"
    begin
        html = open(url).read
        html.encode!("big5")
        page = Nokogiri::HTML.parse html
        hash[:hospital] = "chimei"
        hash[:to_119]        = page.css("#form1 div:nth-child(2) table tr:nth-child(4) td div:nth-child(3) table tr:nth-child(2) td:nth-child(1)").text.strip
        hash[:wait_see]      = page.css("#form1 div:nth-child(2) table tr:nth-child(4) td div:nth-child(3) table tr:nth-child(2) td:nth-child(2)").text.strip
        hash[:emergency_number] = page.css("#form1 div:nth-child(2) table tr:nth-child(4) td div:nth-child(3) table tr:nth-child(2) td:nth-child(3)").text.strip
        hash[:wait_paediatrics] = page.css("#form1 div:nth-child(2) table tr:nth-child(4) td div:nth-child(3) table tr:nth-child(2) td:nth-child(4)").text.strip
        hash[:wait_bed]      = page.css("#form1 div:nth-child(2) table tr:nth-child(4) td div:nth-child(3) table tr:nth-child(2) td:nth-child(5)").text.strip
        hash[:wait_cure_bed] = page.css("#form1 div:nth-child(2) table tr:nth-child(4) td div:nth-child(3) table tr:nth-child(2) td:nth-child(6)").text.strip
        hash[:wait_push_bed] = page.css("#form1 div:nth-child(2) table tr:nth-child(4) td div:nth-child(3) table tr:nth-child(2) td:nth-child(7)").text.strip
    rescue Exception => e
        p e.message
        return nil
    end
    return hash
end