forked from datajules/job_market_web_scraping
-
Notifications
You must be signed in to change notification settings - Fork 0
/
web_scraping_monster.R
67 lines (52 loc) · 1.96 KB
/
web_scraping_monster.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Empleamos la biblioteca para leer códigos web
library('rvest')
library("magrittr")
library("curl")
# Espesificamos el sitio web que vamos a nalizar
# Convertimos la información a texto
# puesto_dataf <- NULL
salario_dataf <- NULL
categoria_dataf <- NULL
direccion_url_dataf <- NULL
fecha_dataf <- NULL
lugar_dataf <- NULL
numvacantes <- NULL
liags <- NULL
sistiempo<-NULL
# Se extraen primero los vínculos de todas las vacantes de INDEED
# for(i in 1:50) {
for(i in seq(0,500,10)) {
if(i==0){
url0 <- paste0("https://www.indeed.com/jobs?q=data+science&l=")
} else {
url0 <- paste0("https://www.indeed.com/jobs?q=data+science&start=",i)
}
#https://www.indeed.com/jobs?q=data+science&start=
# url0 <- curl(paste0("https://www.computrabajo.com.mx/ofertas-de-trabajo/?p=",i,".html", i), handle = curl::new_handle("useragent" = "Mozilla/5.0"))
pagina<-read_html(url0)
#Para el URL
url <- pagina %>% html_nodes('h2.jobtitle') %>% html_nodes('a') %>% html_attr("href")
#sitio<-grepl("/ofertas-de-trabajo/",url,ignore.case = TRUE)
urls <- paste0("https://www.indeed.com",url)
liags <- append(liags,urls)
sistiempo <- append(sistiempo, as.character(Sys.time()))
Sys.sleep(runif(1, .5, 1.5))
cat(i, paste0(Sys.time()), length(urls), "\n")
urls <- NULL
}
data_indeed <- as.data.frame(table(liags))
textos<-NULL
# Se abren todas las vacantes recabadas
for(vacante in liags){
conexion<-curl(vacante, handle = curl::new_handle("useragent" = "LINE Lab - [email protected]"))
pagina<-tryCatch(read_html(conexion), error = function(e) NA)
if(!is.na(pagina)){
texto_vacante <- pagina %>% html_nodes(xpath="/html/body/div[1]/div[3]/div[3]/div/div[1]/div[1]") %>% html_text()
} else {
texto_vacante <- NA
}
textos<-append(textos,texto_vacante)
sistiempo <- append(sistiempo, as.character(Sys.time()))
Sys.sleep(runif(1, 10, 35))
cat(vacante, paste0(Sys.time()), nchar(texto_vacante), substr(texto_vacante,1,30), "\n")
}