hsc

Find High Class Garage

hsc
Feb 25th, 2017
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 2.13 KB | None | 0 0
  1. #車勢網合作修車廠名單,找出有修高級車的車廠#
  2.  
  3. #抓資料#
  4. carce.source <- read_html("http://www.carce.cc/garage/list")
  5. garage.list <- html_nodes(carce.source, "#content a span , .col a")
  6. garage.list.content<-html_text(garage.list)
  7.  
  8. #找出修車廠名字
  9. ##找出還沒被篩出的名字,篩出剩下的關鍵字 = "迪歐星國際" "台灣統華"   "騎轟國際"
  10. garage.company.uname <- garage.list.content[!grepl("車|修|保|輪|馬|區|市|縣|[A-Z,a-z]",garage.list.content)]
  11.  
  12. #車廠名單
  13. garage.company.name <- garage.list.content[grepl("車|修|保|輪|馬|灣|國",garage.list.content)] #找出車廠名
  14. garage.company.name <- garage.company.name[-263] #刪除 非車廠名"太保市"
  15. garage.company.name[286]<- "彰化祥發汽車" #重複車廠重新命名
  16. garage.company.name[261]<-"嘉義中油快保服務中心信義路站" #重複車廠重新命名
  17. garage.company.name                          
  18.  
  19. #車廠名和有修的品牌
  20. garage.list.precise <-garage.list.content[!grepl("區|市|縣",garage.list.content)]
  21. garage.list.precise[2417] <- "彰化祥發汽車" #重複車廠重新命名
  22. garage.list.precise[2218]<-"嘉義中油快保服務中心信義路站" #重複車廠重新命名
  23. garage.list.precise <- append(garage.list.precise,"動力特區車業", after = 1162) #被篩掉的店家名補回來
  24. garage.list.precise
  25.  
  26. #分組與製作列表
  27. loc<-match(garage.company.name, garage.list.precise)
  28. which(!loc == cummax(loc)) #檢查哪裡沒有遞增
  29. idx <- findInterval(seq_along(garage.list.precise), loc)
  30. idx
  31. idx_firms <- garage.company.name[idx]
  32. idx_firms[loc]<-"firms"
  33. output <- split(garage.list.precise, idx_firms)
  34. output$firms <- NULL
  35. head(output, 3L)
  36.  
  37. #無品牌資訊的車廠 特徵為index只出現一次,沒被分進群組
  38. company.name.no.service <- garage.company.name [idx[which(!(idx %in% idx[duplicated(idx)]))]]
  39.  
  40. #查出有高級車品牌服務的店家
  41. length(grep("BMW|Benz|Lexus|Audi|Porsche|VW|Land Rover|Maserati|Ferrari|Cadillac",output)) #260家
  42. highclass.company<-names(output[grep("BMW|Benz|Lexus|Audi|Porsche|VW|Land Rover|Maserati|Ferrari|Cadillac",output)]) #店名
Advertisement
Add Comment
Please, Sign In to add comment