draft/getYuantaBank.R

getYuantaBank <- function(){
  url_A <-c(
    "https://www.yuantabank.com.tw/Bank/location/program/location_bank.aspx?Addr=%A5x%A5_%A5%AB",
    "https://www.yuantabank.com.tw/Bank/location/program/location_bank.aspx?Addr=%A5x%A4%A4%A5%AB",
    "https://www.yuantabank.com.tw/Bank/location/program/location_bank.aspx?Addr=%A5x%ABn%A5%AB",
    "https://www.yuantabank.com.tw/Bank/location/program/location_bank.aspx?Addr=%B0%AA%B6%AF%A5%AB",
    "https://www.yuantabank.com.tw/Bank/location/program/location_bank.aspx?Addr=%B7s%A6%CB%BF%A4",
    "https://www.yuantabank.com.tw/Bank/location/program/location_bank.aspx?Addr=%ABn%A7%EB%BF%A4",
    "https://www.yuantabank.com.tw/Bank/location/program/location_bank.aspx?Addr=%A5x%AAF%BF%A4",
    "https://www.yuantabank.com.tw/Bank/location/program/location_bank.aspx?Addr=%AD%EC%A5x%A5_%BF%A4",
    "https://www.yuantabank.com.tw/Bank/location/program/location_bank.aspx?Addr=%AD%EC%A5x%A4%A4%BF%A4",
    "https://www.yuantabank.com.tw/Bank/location/program/location_bank.aspx?Addr=%AD%EC%A5x%ABn%BF%A4",
    "https://www.yuantabank.com.tw/Bank/location/program/location_bank.aspx?Addr=%AD%EC%B0%AA%B6%AF%BF%A4",
    "https://www.yuantabank.com.tw/Bank/location/program/location_bank.aspx?Addr=%AE%E7%B6%E9%A5%AB",
    "https://www.yuantabank.com.tw/Bank/location/program/location_bank.aspx?Addr=%AD]%AE%DF%BF%A4",
    "https://www.yuantabank.com.tw/Bank/location/program/location_bank.aspx?Addr=%B6%B3%AAL%BF%A4",
    "https://www.yuantabank.com.tw/Bank/location/program/location_bank.aspx?Addr=%A9y%C4%F5%BF%A4",
    "https://www.yuantabank.com.tw/Bank/location/program/location_bank.aspx?Addr=%AB%CC%AAF%BF%A4",
    "https://www.yuantabank.com.tw/Bank/location/program/location_bank.aspx?Addr=%B7s%A6%CB%A5%AB",
    "https://www.yuantabank.com.tw/Bank/location/program/location_bank.aspx?Addr=%B9%FC%A4%C6%BF%A4",
    "https://www.yuantabank.com.tw/Bank/location/program/location_bank.aspx?Addr=%B9%C5%B8q%A5%AB",
    "https://www.yuantabank.com.tw/Bank/location/program/location_bank.aspx?Addr=%AA%E1%BD%AC%BF%A4",
    "https://www.yuantabank.com.tw/Bank/location/program/location_bank.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_extract_all(store1, ".+分行|營業部")
    store3 <- str_replace(unlist(store2), '延時分行', "") 
    store4 <- store3[nchar(store3)>0]
    
    addr1 <- str_extract_all(unlist(info), ".+(號|樓|F)")
    addr2 <- str_replace_all(unlist(addr1),'\t', "")
    addr3 <- addr2[-length(addr2)]
    
    tel1 <- str_extract_all(unlist(info), "\\(.+[0-9]{1}")
    tel2 <- str_replace_all(unlist(tel1),'\t', "")
    
    opn1 <- str_extract_all(unlist(info), "營業時間.+")
    opn2 <- str_replace_all(unlist(opn1), "營業時間","")
    
    data05=data.frame('元大分行', unlist(store4), unlist(tel2), unlist(addr3), unlist(opn2), stringAsFactors=FALSE) 
    data06 <- data05[,-6]
    
    colnames(data06) = c("brand_nm", "store_nm", "tel_no", "addr", "opn_time")
    
    data_sum <- data06
    mylist=rbind(mylist,data_sum)
  }
  mylist
}
leoluyi/CRMaddress documentation built on May 21, 2019, 5:08 a.m.