我正在尝试从Skytrax网站上抓取包括客户评分在内的详细信息。 合并到数据帧中时,出现错误。由于客户评价不适用于某些属性,因此会创建不相等的列,从而导致错误。我希望在没有客户评价的地方填写NA值。
我的代码:
library(rvest)
url= "https://www.airlinequality.com/airline-reviews/air-india/page/1/"
heading= url %>% read_html() %>%html_nodes(".body .text_header") %>% html_text() %>% as.character()
review= url %>% read_html() %>%html_nodes(".text_content") %>% html_text() %>% as.character()
seat_comfort= url %>% read_html() %>%html_nodes(".seat_comfort+ .stars .fill") %>% html_text() %>% as.character()
cabin_service= url %>% read_html() %>%html_nodes(".cabin_staff_service+ .stars .fill") %>% html_text() %>% as.character()
food= url %>% read_html() %>%html_nodes(".food_and_beverages+ .stars .fill") %>% html_text() %>% as.character()
entertainment= url %>% read_html() %>%html_nodes(".inflight_entertainment+ .stars .fill") %>% html_text() %>% as.character()
data= data.frame(heading, review, seat_comfort, cabin_service, food, entertainment)