getLungYen <- function(){
#--經銷商取分頁------------------------------------------------------------------------------------
res <- GET("http://www.lungyengroup.com.tw/Location")
res <- htmlParse(res, encoding = 'utf8')
page_num=xpathSApply(res, '//*[@class="pager"]/a', xmlAttrs)
page_num=length(page_num)
wantURL=list()
for(i in 1:page_num)
{
wantURL[i] <- sprintf('http://www.lungyengroup.com.tw/Location?page=%s', i)
}
#--經銷商取內頁------------------------------------------------------------------------------------
OUTPUT=list()
for(i in 1:page_num)
{
res=htmlParse(wantURL[i], encoding='utf8')
store_nm=xpathSApply(res, '//*[@id="textList"]/li/a/span[@class="infoTxt"]', xmlValue)
tel_no=xpathSApply(res, '//*[@id="textList"]/li/a/span[@class="phone"]', xmlValue)
fax_no=xpathSApply(res, '//*[@id="textList"]/li/a/span[@class="fax"]', xmlValue)
addr=xpathSApply(res, '//*[@id="textList"]/li/a/span[@class="addr"]', xmlValue)
OUTPUT[[i]]= data.frame(brand_nm='龍巖',type='經銷商',store_nm=store_nm,addr=addr,tel_no=tel_no,fax_no=fax_no, data_dt=gsub('-','',Sys.Date()) ,stringsAsFactors=FALSE )
}
FINISH1=do.call(rbind,OUTPUT)
#-----------------------------------------------------------------------------------
#--禮儀服務處取內頁------------------------------------------------------------------------------------
res=htmlParse('http://www.lungyengroup.com.tw/Location?type=1&area=0', encoding='utf8')
store_nm=xpathSApply(res, '//*[@id="textList"]/li/a/span[@class="infoTxt"]', xmlValue)
tel_no=xpathSApply(res, '//*[@id="textList"]/li/a/span[@class="phone"]', xmlValue)
fax_no=xpathSApply(res, '//*[@id="textList"]/li/a/span[@class="fax"]', xmlValue)
addr=xpathSApply(res, '//*[@id="textList"]/li/a/span[@class="addr"]', xmlValue)
OUTPUT= list(data.frame(brand_nm='龍巖',type='禮儀服務處',store_nm=store_nm,addr=addr,tel_no=tel_no,fax_no=fax_no, data_dt=gsub('-','',Sys.Date()) ,stringsAsFactors=FALSE ))
FINISH2=do.call(rbind,OUTPUT)
#--客服櫃台取內頁------------------------------------------------------------------------------------
res=htmlParse('http://www.lungyengroup.com.tw/Location?type=2&area=0', encoding='utf8')
store_nm=xpathSApply(res, '//*[@id="textList"]/li/a/span[@class="infoTxt"]', xmlValue)
tel_no=xpathSApply(res, '//*[@id="textList"]/li/a/span[@class="phone"]', xmlValue)
fax_no=xpathSApply(res, '//*[@id="textList"]/li/a/span[@class="fax"]', xmlValue)
addr=xpathSApply(res, '//*[@id="textList"]/li/a/span[@class="addr"]', xmlValue)
OUTPUT= list(data.frame(brand_nm='龍巖',type='客服櫃台',store_nm=store_nm,addr=addr,tel_no=tel_no,fax_no=fax_no, data_dt=gsub('-','',Sys.Date()) ,stringsAsFactors=FALSE ))
FINISH3=do.call(rbind,OUTPUT)
#--墓園取內頁------------------------------------------------------------------------------------
res=htmlParse('http://www.lungyengroup.com.tw/Location?type=3&area=0', encoding='utf8')
store_nm=xpathSApply(res, '//*[@id="textList"]/li/a/span[@class="infoTxt"]', xmlValue)
tel_no=xpathSApply(res, '//*[@id="textList"]/li/a/span[@class="phone"]', xmlValue)
fax_no=xpathSApply(res, '//*[@id="textList"]/li/a/span[@class="fax"]', xmlValue)
addr=xpathSApply(res, '//*[@id="textList"]/li/a/span[@class="addr"]', xmlValue)
OUTPUT= list(data.frame(brand_nm='龍巖',type='墓園塔位',store_nm=store_nm,addr=addr,tel_no=tel_no,fax_no=fax_no, data_dt=gsub('-','',Sys.Date()) ,stringsAsFactors=FALSE ))
FINISH4=do.call(rbind,OUTPUT)
#--會館取內頁------------------------------------------------------------------------------------
res=htmlParse('http://www.lungyengroup.com.tw/Location?type=4&area=0', encoding='utf8')
store_nm=xpathSApply(res, '//*[@id="textList"]/li/a/span[@class="infoTxt"]', xmlValue)
tel_no=xpathSApply(res, '//*[@id="textList"]/li/a/span[@class="phone"]', xmlValue)
fax_no=xpathSApply(res, '//*[@id="textList"]/li/a/span[@class="fax"]', xmlValue)
addr=xpathSApply(res, '//*[@id="textList"]/li/a/span[@class="addr"]', xmlValue)
OUTPUT= list(data.frame(brand_nm='龍巖',type='會館',store_nm=store_nm,addr=addr,tel_no=tel_no,fax_no=fax_no, data_dt=gsub('-','',Sys.Date()) ,stringsAsFactors=FALSE ))
FINISH5=do.call(rbind,OUTPUT)
FINISH=rbind(FINISH1,FINISH2,FINISH3,FINISH4,FINISH5)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.