draft/getGongCha.R

getGongCha <- function(){
  wantURL <- 'http://www.gong-cha.com/location.php'
  res <- GET(wantURL, encoding='utf8')
  res2 <- content(res, encoding='utf8')
  store_nm=xpathSApply(res2, '//*[@class="location_list"]/tr[1]', xmlValue)
  store_nm <- str_replace_all(store_nm, '(\r|\n| | |店別:)+', '')
  addr=xpathSApply(res2, '//*[@class="location_list"]/tr[2]', xmlValue)
  addr <- str_replace_all(addr, '(\r|\n| | |地址:)+', '')
  addr <- str_replace_all(addr, '([(]).+$', '')
  tel_no=xpathSApply(res2, '//*[@class="location_list"]/tr[3]', xmlValue)
  tel_no <- str_replace_all(tel_no, '(\r|\n| | |電話:)+', '')
  OUTPUT= data.frame(brand_nm='貢茶',store_nm=store_nm,addr=addr,tel_no=tel_no, data_dt=gsub('-','',Sys.Date()) ,stringsAsFactors=FALSE )
  return(OUTPUT)
}
leoluyi/CRMaddress documentation built on May 21, 2019, 5:08 a.m.