draft/getYoshinoya.R

getYoshinoya <- function(){
  website="http://www.yoshinoya.com.tw/"
  url="http://www.yoshinoya.com.tw/02store/s01.php?type=all"
  res=GET(url)
  con=content(res,"text",encoding="UTF-8")
  con_par=htmlParse(con,encoding="UTF8")
  #各分店的連結
  store_link=xpathSApply(con_par,"//a[@class='maplist']",xmlGetAttr,'href')
  #各分店的名稱
  store_nm=xpathSApply(con_par,"//a[@class='maplist']",xmlValue)
  #分店數
  store_cnt=length(store_link)
  addr=c(); tel_no=c(); open_time=c(); breakfast=c(); fried=c()
  coffee=c(); wifi=c()
  #gisX=c()
  #gisY=c()
  for(i in 1:store_cnt){
    link=paste(website,"02store/",store_link[i],sep="")
    link_res=GET(link)
    link_con=content(link_res,"text",encoding="UTF-8")
    link_con_par=htmlParse(link_con,encoding="UTF8")
    detail=xpathSApply(link_con_par,"//td[@class='text001']",xmlValue,trim=TRUE)
    service=xpathSApply(link_con_par,"//td[@class='text001']/img",xmlGetAttr,'src')
    addr[i]=detail[1]
    tel_no[i]=detail[2]
    open_time[i]=detail[3]
    if (detail[4]=="") {breakfast[i]="N"} else{breakfast[i]="Y"}
    if (detail[5]=="") {fried[i]="N"} else{fried[i]="Y"}
    if (detail[6]=="") {coffee[i]="N"} else{coffee[i]="Y"}
    if (detail[7]=="") {wifi[i]="N"} else{wifi[i]="Y"}
  }
  
  final_data=data.frame("brand_nm"= "吉野家", store_nm, addr, tel_no, open_time, store_link,
                        breakfast, fried, coffee, wifi)
  return(final_data)
}
leoluyi/CRMaddress documentation built on May 21, 2019, 5:08 a.m.