celestialgod

parsing html tables v2

Jul 3rd, 2016
234
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. library(xml2)
  2. library(httr)
  3. library(pipeR)
  4. library(stringi)
  5. library(rvest)
  6. Sys.setlocale("LC_ALL", 'C')
  7.  
  8. tables <- sapply(1:7, function(i){
  9.   tmp <- paste0("http://www.i-write.idv.tw/life/info/familymart/familymart1-", i, ".html") %>>%
  10.     GET %>>% content(encoding = "UTF-8") %>>% html_nodes("table") %>>% '[['(3) %>>%
  11.     html_table %>>% as.matrix
  12.   tmp %>>% stri_conv(from = "UTF-8", to = "Big5") %>>% matrix(nrow(tmp))
  13. })
  14.  
  15. #      [,1]           [,2]          [,3]                           [,4]                
  16. # [1,] "門市名稱"     "門市電話"    "門市地址"                     "門市代號"          
  17. # [2,] "七堵工明店"   "02-24519520" "基隆市七堵區工建路1之15號1樓" "服務代號: 50268"  
  18. # [3,] "七堵工建店"   "02-24527145" "基隆市七堵區工建路4號"        "服務代號:"        
  19. # [4,] "七堵永富店"   "02-24558170" "基隆市七堵區永富路120號"      "服務代號:    15827"
  20. # [5,] "七堵新明德店" "02-24517467" "基隆市七堵區明德二路15之53號" "服務代號:    50035"
  21. # [6,] "七堵大興店"   "02-24560059" "基隆市七堵區南興路30號"       "服務代號:    11444"
  22. # [7,] "七堵大華店"   "02-24563412" "基隆市七堵區南興路85號"       "服務代號:    11142"
  23. # [8,] "基隆百福店"   "02-24529098" "基隆市七堵區福二街204號"      "服務代號:    15172"
RAW Paste Data