1 # Render Multiple URLs to file
3 system = require("system")
6 # @param array of URLs to render
7 # @param callbackPerUrl Function called after finishing each URL, including the last URL
8 # @param callbackFinal Function called after finishing everything
9 RenderUrlsToFile = (urls, callbackPerUrl, callbackFinal) ->
10 urlIndex = 0 # only for easy file naming
11 webpage = require("webpage")
14 "rendermulti-" + urlIndex + ".png"
16 next = (status, url, file) ->
18 callbackPerUrl status, url, file
25 page = webpage.create()
30 page.settings.userAgent = "Phantom.js bot"
31 page.open "http://" + url, (status) ->
33 if status is "success"
36 next status, url, file
39 next status, url, file
46 if system.args.length > 1
47 arrayOfUrls = Array::slice.call(system.args, 1)
49 # Default (no args passed)
50 console.log "Usage: phantomjs render_multi_url.js [domain.name1, domain.name2, ...]"
51 arrayOfUrls = ["www.google.com", "www.bbc.co.uk", "www.phantomjs.org"]
53 RenderUrlsToFile arrayOfUrls, ((status, url, file) ->
54 if status isnt "success"
55 console.log "Unable to render '" + url + "'"
57 console.log "Rendered '" + url + "' at '" + file + "'"