Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #車勢網合作修車廠名單,找出有修高級車的車廠#
- #抓資料#
- carce.source <- read_html("http://www.carce.cc/garage/list")
- garage.list <- html_nodes(carce.source, "#content a span , .col a")
- garage.list.content<-html_text(garage.list)
- #找出修車廠名字
- ##找出還沒被篩出的名字,篩出剩下的關鍵字 = "迪歐星國際" "台灣統華" "騎轟國際"
- garage.company.uname <- garage.list.content[!grepl("車|修|保|輪|馬|區|市|縣|[A-Z,a-z]",garage.list.content)]
- #車廠名單
- garage.company.name <- garage.list.content[grepl("車|修|保|輪|馬|灣|國",garage.list.content)] #找出車廠名
- garage.company.name <- garage.company.name[-263] #刪除 非車廠名"太保市"
- garage.company.name[286]<- "彰化祥發汽車" #重複車廠重新命名
- garage.company.name[261]<-"嘉義中油快保服務中心信義路站" #重複車廠重新命名
- garage.company.name
- #車廠名和有修的品牌
- garage.list.precise <-garage.list.content[!grepl("區|市|縣",garage.list.content)]
- garage.list.precise[2417] <- "彰化祥發汽車" #重複車廠重新命名
- garage.list.precise[2218]<-"嘉義中油快保服務中心信義路站" #重複車廠重新命名
- garage.list.precise <- append(garage.list.precise,"動力特區車業", after = 1162) #被篩掉的店家名補回來
- garage.list.precise
- #分組與製作列表
- loc<-match(garage.company.name, garage.list.precise)
- which(!loc == cummax(loc)) #檢查哪裡沒有遞增
- idx <- findInterval(seq_along(garage.list.precise), loc)
- idx
- idx_firms <- garage.company.name[idx]
- idx_firms[loc]<-"firms"
- output <- split(garage.list.precise, idx_firms)
- output$firms <- NULL
- head(output, 3L)
- #無品牌資訊的車廠 特徵為index只出現一次,沒被分進群組
- company.name.no.service <- garage.company.name [idx[which(!(idx %in% idx[duplicated(idx)]))]]
- #查出有高級車品牌服務的店家
- length(grep("BMW|Benz|Lexus|Audi|Porsche|VW|Land Rover|Maserati|Ferrari|Cadillac",output)) #260家
- 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