Created
September 1, 2016 18:32
-
-
Save atorralb/f221560e634f95f8e898917008adbc5b to your computer and use it in GitHub Desktop.
bot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//DEBUG=nightmare* Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 & node --harmony app.js | |
'use strict'; | |
var Nightmare = require('nightmare'); | |
var vo = require('vo'); | |
var occ = require ('./nightmare-occ'); | |
var nightmare = new Nightmare({ | |
widt: 1200, | |
height:1800, | |
show: true, | |
'webPreferences':{ | |
webSecurity: false, | |
partition: 'persist:', | |
images: false, | |
webaudio: false, | |
webgl: false | |
} | |
}); | |
/* | |
var parsePage = function(url){ | |
nightmare | |
.goto(url) | |
.wait(10000) | |
.evaluate(function(){ | |
var results =[]; | |
var selector = document.documentElement.querySelectorAll('#normalook_mod_sr .title_modn_sr a'); | |
for (x=0; x<selector.length; x++){ | |
results.push(document.documentElement.querySelectorAll('#normalook_mod_sr .title_modn_sr a')[x].href); | |
} | |
return results; | |
}) | |
.end() | |
.then(function(result){ | |
console.log(result); | |
console.log(result.length); | |
}) | |
} | |
*/ | |
var parsePage = function(searchString){ | |
nightmare | |
.goto(searchString) | |
.wait(10000) | |
.evaluate(function(){ | |
var results =[]; | |
var selector = document.documentElement.querySelectorAll('#normalook_mod_sr .title_modn_sr a'); | |
for (x=0; x<selector.length; x++){ | |
results.push(document.documentElement.querySelectorAll('#normalook_mod_sr .title_modn_sr a')[x].href); | |
} | |
return results; | |
}) | |
.end() | |
.then(function(result){ | |
console.log(result) | |
}) | |
}; | |
var getEmail = function(url){ | |
nightmare | |
.goto(url) | |
.wait(1000) | |
.evaluate(function(){ | |
function extractEmails ( text ){ | |
return text.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi); | |
} | |
var email = extractEmails(document.documentElement.querySelector('#tittlejob_jo').textContent); | |
var job_position = document.documentElement.querySelector('[itemprop=title]').textContent; | |
//var corp = document.documentElement.querySelector('[itemprop=name]').textContent; | |
//var contact = document.documentElement.querySelector('[itemprop=address] [itemprop=name]').textContent; | |
//var tel= document.documentElement.querySelector('[itemprop=telephone]').textContent; | |
if(email){ | |
return email[0]; | |
}else{ | |
console.log('empty') | |
} | |
}) | |
.end() | |
.then(function(result){ | |
console.log(result) | |
}) | |
}; | |
var url = 'https://www.occ.com.mx/Empleo/Oferta/9243223-ejecutivo-a-de-cuenta-para-tulancingo-de-bravo'; | |
getEmail(url); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i'm so drunk ^_^