Created
March 28, 2015 16:38
-
-
Save nch7/7ff2cc8a3a16896127a7 to your computer and use it in GitHub Desktop.
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
var casper = require('casper').create({ | |
verbose: true, | |
logLevel: "error" | |
}) | |
fs = require('fs') | |
requiredParams = ['urls'] | |
response = {"status":"","error":"","data":[],"logs":[]} | |
startTime = new Date().getTime() | |
function exit(){ | |
endTime = new Date().getTime() | |
response['time'] = (endTime-startTime)/1000 | |
response = JSON.stringify(response) | |
casper.echo(response) | |
casper.capture('last.png') | |
casper.exit() | |
} | |
function fail(reason){ | |
response['status'] = 'fail' | |
response['error'] = reason | |
exit() | |
} | |
urls_file = casper.cli.get('urls'); | |
urls = fs.read(urls_file) | |
requiredParams.forEach(function(el){ | |
if (!casper.cli.has(el)){ | |
fail(el+' Not provided') | |
} | |
}) | |
casper.options.waitTimeout = 20000 | |
if(!fs.exists('screens')){ | |
fs.makeDirectory('screens') | |
} | |
casper.start() | |
casper.userAgent('Mozilla/5.0 (Macintosh Intel Mac OS X)') | |
casper.thenOpen('https://www.dynadot.com/domain/bulk-search.html',function(){ | |
this.capture('screens/1.0.png') | |
this.waitForSelector("form[action='/domain/bulk-search.html'] input[type='submit']",function(){ | |
this.evaluate(function(domains){ | |
document.querySelector("form[action='/domain/bulk-search.html'] input[name='tld'][value='1']").checked=true | |
document.querySelector("form[action='/domain/bulk-search.html'] textarea[name='domains']").value = domains | |
},urls) | |
this.click("form[action='/domain/bulk-search.html'] input[type='submit']") | |
}) | |
this.capture('screens/1.1.png') | |
}) | |
casper.then(function(){ | |
this.capture('screens/2.0.png') | |
}) | |
casper.then(function(){ | |
this.capture('screens/3.0.png') | |
this.waitForSelector('.redesign-table',function(){ | |
var AvailableDomains = this.evaluate(function(){ | |
AvailableDomains = []; | |
$(function(){ | |
$('.autocheck').parent().find("+ td span[style='font-weight: bold;']").each(function(index,el){ | |
AvailableDomains.push($(el).text()) | |
}) | |
}) | |
return AvailableDomains | |
}) | |
this.capture('screens/3.1.png') | |
response['data']=AvailableDomains | |
response['status']='success' | |
exit() | |
}) | |
}) | |
casper.then(function(){ | |
this.capture('screens/4.0.png') | |
fail('something went wrong') | |
}) | |
casper.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment