draft/getWellCare.R

getWellCare <- function(){
  
  URL='http://www.wellcare.com.tw/wellindex/03map.htm'
  res <- GET(URL, encoding='big5')
  res2 <- htmlParse(content(res, "text", encoding = "big5"), encoding = "utf8")
  store_area <- cssApply(res2,"map>area",cssLink)
  store_area<-store_area[33:length(store_area)]
  
  getwelllink <- function(URL){
    URL=URLencode(URL)
    res3 <- GET(URL, encoding='big5')
    res4 <- htmlParse(content(res3, "text", encoding = "utf8"), encoding = "utf8")
    store_link <- unlist(cssApply(res4,"tr > td a",cssLink))
    return(store_link)
  }
  getwellinfo <- function(URL){
    #URL="http://www.wellcare.com.tw/wellindex/new-map/page/if-13/13JIA%20YI-7.htm"
    URL=str_replace_all(URL,'%20',' ')
    URL=URLencode(URL)
    #URL=URLencode("http://www.wellcare.com.tw/wellindex/new-map/page/if-2/2-newtaipei-15.htm")
    res5 <- GET(URL, encoding='big5')
    res6 <- htmlParse(content(res5, "text", encoding = "big5"), encoding = "utf8")
    store_nm <- cssApply(res6,"span.style7",cssCharacter)
    store_nm<-str_replace_all(store_nm,'[:space:]','')
    store_info <- cssApply(res6,"table table > tr > td",cssCharacter)
    tel_no<-store_info[6]
    addr<-store_info[7]
    addr<-str_replace_all(addr,'[:space:]','')
    time<-paste(store_info[8:10],collapse = " ")
    time<-str_replace_all(time,'[:space:]','')
    brand_nm<-'維康醫療'
    result <- data.frame(brand_nm=brand_nm,store_nm=store_nm, addr=addr, tel_no=tel_no, time=time,
                         stringsAsFactors=FALSE )
  }
  wellinfo <- unlist(lapply(store_area,getwelllink))
  wellinfo2 <- lapply(wellinfo,getwellinfo)
  wellinfo3 <- do.call(rbind, wellinfo2)
}
leoluyi/CRMaddress documentation built on May 21, 2019, 5:08 a.m.