draft/getYuantaATM.R

getYuantaATM <- function(){
  url_A <-c(
    "https://www.yuantabank.com.tw/Bank/location/program/location_atm.aspx?Addr=%A5x%A5_%A5%AB",
    "https://www.yuantabank.com.tw/Bank/location/program/location_atm.aspx?Addr=%A5x%A4%A4%A5%AB",
    "https://www.yuantabank.com.tw/Bank/location/program/location_atm.aspx?Addr=%A5x%ABn%A5%AB",
    "https://www.yuantabank.com.tw/Bank/location/program/location_atm.aspx?Addr=%B0%AA%B6%AF%A5%AB",
    "https://www.yuantabank.com.tw/Bank/location/program/location_atm.aspx?Addr=%B0%F2%B6%A9%A5%AB",
    "https://www.yuantabank.com.tw/Bank/location/program/location_atm.aspx?Addr=%B7s%A6%CB%BF%A4",
    "https://www.yuantabank.com.tw/Bank/location/program/location_atm.aspx?Addr=%ABn%A7%EB%BF%A4",
    "https://www.yuantabank.com.tw/Bank/location/program/location_atm.aspx?Addr=%A5x%AAF%BF%A4",
    "https://www.yuantabank.com.tw/Bank/location/program/location_atm.aspx?Addr=%AD%EC%A5x%A5_%BF%A4",
    "https://www.yuantabank.com.tw/Bank/location/program/location_atm.aspx?Addr=%AD%EC%A5x%A4%A4%BF%A4",
    "https://www.yuantabank.com.tw/Bank/location/program/location_atm.aspx?Addr=%AD%EC%A5x%ABn%BF%A4",
    "https://www.yuantabank.com.tw/Bank/location/program/location_atm.aspx?Addr=%AD%EC%B0%AA%B6%AF%BF%A4",
    "https://www.yuantabank.com.tw/Bank/location/program/location_atm.aspx?Addr=%AE%E7%B6%E9%A5%AB",
    "https://www.yuantabank.com.tw/Bank/location/program/location_atm.aspx?Addr=%AD]%AE%DF%BF%A4",
    "https://www.yuantabank.com.tw/Bank/location/program/location_atm.aspx?Addr=%B6%B3%AAL%BF%A4",
    "https://www.yuantabank.com.tw/Bank/location/program/location_atm.aspx?Addr=%A9y%C4%F5%BF%A4",
    "https://www.yuantabank.com.tw/Bank/location/program/location_atm.aspx?Addr=%AB%CC%AAF%BF%A4",
    "https://www.yuantabank.com.tw/Bank/location/program/location_atm.aspx?Addr=%B7s%A6%CB%A5%AB",
    "https://www.yuantabank.com.tw/Bank/location/program/location_atm.aspx?Addr=%B9%FC%A4%C6%BF%A4",
    "https://www.yuantabank.com.tw/Bank/location/program/location_atm.aspx?Addr=%B9%C5%B8q%A5%AB",
    "https://www.yuantabank.com.tw/Bank/location/program/location_atm.aspx?Addr=%AA%E1%BD%AC%BF%A4",
    "https://www.yuantabank.com.tw/Bank/location/program/location_atm.aspx?Addr=%AA%F7%AA%F9%BF%A4")
  
  mylist <- list()
  for (i in 1:length(url_A)){
    url <- url_A[i]
    res <- GET(url, encoding='big5')
    res2 <- content(res,"text", encoding='big5')
    html <- htmlParse(res2, encoding = "utf8")
    tables <- readHTMLTable(html)
    
    store <- cssApply(html,"tr > td .text-area", cssCharacter)
    info <-  cssApply(html,"tr > td .text01", cssCharacter)
    
    store1 <- str_replace_all(unlist(store),'\t|\r|\n', "")
    store2 <- str_replace_all(store1, '.+據點', "")
    store3 <- str_replace_all(store2, '.+顯示於下方。', "") 
    store4 <- store3[nchar(store3)>0]
    
    addr1 <- str_extract_all(unlist(info), ".+(號|樓|F)")
    addr2 <- str_replace_all(unlist(addr1),'\t', "")
    
    addr3 <- addr2[-length(addr2)]
    
    data05=data.frame('元大ATM', unlist(store4), unlist(addr3), stringAsFactors=FALSE) 
    data06 <- data05[,-4]
    
    colnames(data06) = c("brand_nm", "store_nm", "addr")
    
    data_sum <- data06
    mylist=rbind(mylist,data_sum)
  }
  return(mylist)
}
leoluyi/CRMaddress documentation built on May 21, 2019, 5:08 a.m.