To use session-wide Zyte Smart Proxy Manager(formerly Crawlera) proxy with PhantomJs or CasperJS provide --proxy=proxy.zyte.com:8011 and --proxy-auth=<API key>: arguments to PhantomJS (CasperJS passes these arguments to PhantomJS).

Example:


casperjs|phantomjs --proxy="proxy.zyte.com:8011" --proxy-auth="<API KEY>:''" yourscript.js


When making HTTPS requests, you should provide path to zyte-smartproxy-ca.crt.

Example:


phantomjs --ssl-protocol=any --proxy="proxy.zyte.com:8011" --proxy-auth="<API KEY>:''" --ssl-client-certificate-file=/PATH/zyte-smartproxy-ca.crt phantomjs/examples/rasterize.js  https://twitter.com twitter.jpg


SpookyJS allows you to spawn multiple instances of CasperJS suites, so proxy and proxy-auth arguments should be provided when creating a Spooky object.

Example:


var spooky = new Spooky({
child: {
proxy: 'proxy.zyte.com:8011',
proxy-auth: '<API key>:'
/* ... */
},
/* ... */
},


If it’s preferred that Smart Proxy Manager operated only on specific URLs, they should be wrapped according to Fetch API.

Example in CasperJS:


var casper = require('casper').create();
casper.start();
// always encode url components !
var url_to_crawl = encodeURIComponent('http://wtfismyip.com/text'); // results in http%3A%2F%2Fwtfismyip.com%2Ftext
// You can either
// Authenticate session wide:
casper.setHttpAuth('<API key>', '');
casper.open('http://proxy.zyte.com:8011/fetch?url=' + url_to_crawl);
// or incorporate authentication into the url:
casper.open('http://<API key>:@proxy.zyte.com:8011/fetch?url=' + url_to_crawl);

casper.then(function(response) {
this.echo(response.url);
this.echo(response.status);
this.debugHTML(); // print page source
});
casper.run();