# Hello, world!
#
# This is an example function named 'hello'
# which prints 'Hello, world!'.
#
# You can learn more about package authoring with RStudio at:
#
# http://r-pkgs.had.co.nz/
#
# Some useful keyboard shortcuts for package authoring:
#
# Build and Reload Package: 'Ctrl + Shift + B'
# Check Package: 'Ctrl + Shift + E'
# Test Package: 'Ctrl + Shift + T'
#' Title
#'
#' @param company
#'
#' @return
#' @export
#'
#' @examples
getFromMondays <- function(company) {
Sys.setlocale(locale = "Portuguese")
pageNumber = 1
itens = vector()
values <- vector()
dates <- vector()
descriptions <- vector()
repeat{
base <- xml2::read_html(paste(paste(paste("https://www.lovemondays.com.br/trabalhar-na-",company,sep=""),"/avaliacoes/pagina/",sep=""),pageNumber,sep=""))
value <- base %>% rvest::html_nodes(".lm-RatingStar-starContainer-starsActive") %>% rvest::html_attr("style") %>% readr::parse_number()
check <- base %>% rvest::html_nodes("#sectors") %>% rvest::html_text() %>% readr::parse_character() %>% stringr::str_replace_all("[\r\n]" , "")
if(length(check)>0){
value <- value[-c((length(value)-2):length(value))]
}
item <- base %>% rvest::html_nodes(".lm-OverallValuation-ratingsList-item , .lm-Typography--smallMargin strong, .dropdown-header, .lm-RatingStartButton, .lm-RatingStar--flexStart") %>% rvest::html_text() %>% stringr::str_replace_all("[\r\n]" , "")
date <- c("Geral",base %>% rvest::html_nodes(".lm-Company-dateTime-label") %>% rvest::html_text() %>% readr::parse_character() %>% stringr::str_replace_all("[\r\n]" , ""))
description <- base %>% rvest::html_nodes(".is-large .lm-List-item-wrapper") %>% rvest::html_text() %>% readr::parse_character() %>% stringr::str_replace_all("[\r\n]" , "|") %>% stringr::str_replace_all("\\|{2,20}","\\|")
if(length(item)==0){
break
}
itens <- c(itens,item)
values <- c(values,value)
dates <- c(dates,date)
descriptions <- c(descriptions,description)
pageNumber = pageNumber + 1
}
dates <- dates[dates != "Geral"]
results <- data.frame(attribute=itens,value=values)
results$attribute <- as.character(results$attribute)
results$attribute <- as.character(results$attribute)
results$attribute[results$attribute == ""] <- "Satisfa??o Geral"
results$type <- ifelse(stringr::str_sub(results$attribute,-1) %>% stringr::str_detect("[0-9]")| results$attribute == "Satisfação geral dos funcionários","Geral","Individual")
results$attribute <- stringr::str_replace_all(results$attribute,"[0-9].*[0-9]","")
results <- results[c(1:nrow(results)) <= 5 | (c(1:nrow(results)) > 5 & results$type == "Individual"),]
results$ID = NA
results$date = NA
valID <- nrow(results[substr(results$attribute,0,7) == "Satisfa" & results$type=="Individual",])+1
for(i in 1:nrow(results)){
if(i > 5 & substr(results$attribute[i],0,7)=="Satisfa"){
valID = valID - 1
}
results$ID[i] <- valID
results$date[i] <- dates[valID]
results$description[i] <- descriptions[valID]
}
results$ID[1:5] <- 0
results$date[1:5] <- "Não se aplica"
results$company <- company
results$attribute[substr(results$attribute,0,7)=="Satisfa"] <- "Satisfação Geral"
results <-tidyr::spread(data=results[!is.na(results$value),],key=attribute,value=value)
results$pros <- stringr::str_extract(results$description,"\\|[P][r][ó][s](.*?)\\|") %>% stringr::str_replace_all("\\|","") %>% stringr::str_replace_all("Prós:","")
results$cons <- stringr::str_extract(results$description,"\\|[C][o][n][t][r][a][s](.*?)\\|") %>% stringr::str_replace_all("\\|","") %>% stringr::str_replace_all("Contras:","")
results$recommends <- stringr::str_extract(results$description,"\\|[:alpha:]{3}\\|") %>% stringr::str_replace_all("\\|","")
results$recommends[is.na(results$recommends)] = "NA"
results$jobTitle <- stringr::str_extract(results$description,"\\|(.*?)\\|") %>% stringr::str_replace_all("\\|","") %>% stringr::str_replace_all("[,]\\ [s][a][i][u](.*)","") %>% stringr::str_replace_all("Ex[-]funcionário","")
results$jobTitle <- ifelse(results$jobTitle %in% c("Funcionário",""),"Desconhecido",results$jobTitle)
results <- results[,!names(results) %in% c("description")]
return(results)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.