Created
September 16, 2015 16:20
-
-
Save alvises/e9822ed8c2c0e4c4e6fc 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 url, contentType; | |
casper.start(....) | |
//download time | |
//waitForResource because sometime the server is redirecting multiple time | |
//the browser, so we need the final url to download it as pdf (or render it as html) | |
.waitForResource(function testResource(resource) { | |
console.log("resource: "+resource.status+" : "+resource.contentType+" : "+resource.url); | |
if(resource.status == 200) { | |
url = resource.url; | |
contentType = resource.contentType; | |
} | |
return resource.status == 200 | |
},function onResourceReceived(resource){ | |
console.log("contentType: "+resource.contentType); | |
}) | |
.then(function() { | |
//we could also use the "contentType" to distinguish pdf to html | |
if(url.indexOf(".pdf") > 0) { | |
//there is a pdf to download | |
console.log("downloading pdf: "+downloadPath+" - "+url); | |
this.download(url,downloadPath); | |
} else { | |
//there is an html page to convert | |
console.log("capturing html: "+downloadPath+" - "+url); | |
this.capture(downloadPath); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment