draft/getCiti.R

getCiti <- function(){
  URL='http://www.citibank.com.tw/sim/zh-tw/common/serviceCenter.htm?filter=branchLocation'
  res <- GET(URL, encoding='utf8')
  res2 <- htmlParse(content(res, "text", encoding = "utf8"), encoding = "utf8")
  store_nm <- cssApply(res2,"div.tabContent%20active_content div.showHideArea>div.showHideCont>table.clsTable%20dropshadow%20rounded tr.cLsWhite > td",cssCharacter)
  store_cn <- cssApply(res2,"div.tabContent%20active_content div.showHideArea>div.showHideCont>table.clsTable%20dropshadow%20rounded tr.cLsWhite > td",cssCharacter)
  
  tables <- readHTMLTable(res2,header = FALSE)
  data_table <- do.call(rbind, tables)
  store_info<-data_table[,1]
  store_info<-str_replace_all(store_info,'[:space:]+',' ')
  store_nm<-str_replace_all(str_extract(store_info,'.+地址:'),'[:space:]|地址:','')
  addr<-str_replace_all(str_extract(store_info,'地址.+電話:'),'[:space:]|電話:|地址:','')
  tel_no<-str_replace_all(str_extract(store_info,'電話:\\([0-9]+\\)[0-9]+-[0-9]+'),'[:space:]|電話:','')
  location<-str_replace_all(str_extract(store_info,'座落地點:.+自動'),'[:space:]|座落地點:|自動','')
  ATM<-str_replace_all(str_extract(store_info,'自動櫃員機存款服務:.+'),'[:space:]|。','')
  
  brand_nm<-'花旗銀行'
  store_info2<-data.frame(brand_nm,store_nm,addr,tel_no,location,ATM, stringsAsFactors = FALSE)
  store_info2 <- store_info2[!is.na(store_info2$store_nm), ]
  return(store_info2)
}
leoluyi/CRMaddress documentation built on May 21, 2019, 5:08 a.m.