Created
August 17, 2016 22:30
-
-
Save jamlfy/035c47b34ea61a25c15a83918ab71efa to your computer and use it in GitHub Desktop.
Modificador de encuestas caracol
This file contains hidden or 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
console.log('Loading a web page'); | |
var page = require('webpage').create(); | |
var url = 'http://noticias.caracoltv.com/'; | |
page.settings.userAgent = 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2225.0 Safari/537.36'; | |
var JQUERY = 'http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js'; | |
var blockedResources = [ | |
'ads.rubiconproject.com', | |
'snapwidget.com', | |
'google-analytics.com', | |
'api.mixpanel.com', | |
'fonts.googleapis.com', | |
'stats.g.doubleclick.net', | |
'mc.yandex.ru', | |
'use.typekit.net', | |
'beacon.tapfiliate.com', | |
'js-agent.newrelic.com', | |
'api.segment.io', | |
'woopra.com', | |
'\\.ttf', | |
'\\.css', | |
'static.olark.com', | |
'static.getclicky.com', | |
'fast.fonts.com', | |
'youtube.com\/embed', | |
'cdn.heapanalytics.com', | |
'googleads.g.doubleclick.net', | |
'pagead2.googlesyndication.com', | |
'fullstory.com/rec', | |
'navilytics.com/nls_ajax.php', | |
'\\.eot', | |
'log.optimizely.com/event', | |
'\\.otf', | |
'hn.inspectlet.com', | |
'tpc.googlesyndication.com', | |
'partner.googleadservices.com' | |
]; | |
page.onResourceRequested = function (requestData, networkRequest) { | |
for(var i = 0,l = blockedResources.length; i < l; i++) { | |
var regex = new RegExp(blockedResources[i], 'gi'); | |
if(regex.test(requestData.url)) { | |
networkRequest.cancel(); | |
break; | |
} | |
} | |
}; | |
page.viewportSize = { width: 1280, height: 780 }; | |
page.open(url, function (status) { | |
if (status !== 'success') { | |
console.log('Unable to access network'); | |
} else { | |
page.includeJs(JQUERY, function() { | |
console.log('Injecion de jQuery'); | |
page.evaluate(function() { | |
console.log('Inicio'); | |
var TIMER = 500; | |
var isColect = $ || jQuery; | |
var nameButton = 'a#pd-vote-button9499518'; | |
var nameRespuesta = 'input#PDI_answer43353901'; | |
var status = 1; | |
var boton = null; | |
var respuesta = null; | |
var timer = setInterval(function () { | |
console.log('Yeah', status); | |
if(status == 2){ | |
respuesta.click(); | |
status++; | |
console.log('Presiono Respuesta'); | |
} else if(status == 3){ | |
boton.click(); | |
status++; | |
console.log('Presiono Boton'); | |
} else if( status == 4){ | |
if(timer){ | |
clearInterval(timer); | |
timer = null; | |
} | |
console.log('VOTANCION'); | |
} else if( !boton || !respuesta ) { | |
boton = boton || isColect(nameButton); | |
respuesta = respuesta || isColect(nameRespuesta); | |
if(boton && respuesta){ | |
status++; | |
} | |
} | |
}, TIMER); | |
}); | |
//phantom.exit(); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment