PhantomJS
Using Zyte Smart Proxy Manager(formerly Crawlera) in Phantom object:
var page = require('webpage').create(); phantom.setProxy('proxy.zyte.com', '8011', 'http') // change to https when making HTTPS requests and port to 8014 page.customHeaders={'Proxy-Authorization': 'Basic '+btoa('APIKEY:')}; // Make sure to include ':' at the end page.open('http://httpbin.org/ip', function (status) { page.evaluate(function(){}); console.log(page.content); phantom.exit(); });
to run use:
phantomjs myscript.js
add '--ignore-ssl-errors=true' when making HTTPS request.
Using Smart Proxy Manager in Page object:
var page = require('webpage').create(); page.setProxy('http://proxy.zyte.com:8011/'); // change scheme to https:// when making HTTPS requests and port to 8014 page.customHeaders={'Proxy-Authorization': 'Basic '+btoa('APIKEY:')}; // Make sure to include ':' at the end page.open('http://httpbin.org/ip', function (status) { page.evaluate(function(){}); console.log(page.content); phantom.exit(); });
to run use:
phantomjs myscript.js
add '--ignore-ssl-errors=true' when making HTTPS request.
Using Smart Proxy Manager in Phantom object with arguments:
var page = require('webpage').create(),
system = require('system'),
host, port, scheme, apikey, address;
host = system.args[1];
port = system.args[2];
scheme = system.args[3];
apikey = system.args[4];
address = system.args[5];
phantom.setProxy(host, port, scheme);
page.customHeaders={'Proxy-Authorization': 'Basic '+btoa(apikey)};
page.open(address, function (status) {
page.evaluate(function(){});
console.log(page.content);
phantom.exit();
});
to run use:
phantomjs myscript.js 'proxy.zyte.com' '8011' '<http or https>' '<APIKEY>:' 'http://httpbin.org/ip' // Make sure to include ':' at the end
add '--ignore-ssl-errors=true' when making HTTPS request.
Using Smart Proxy Manager in Page object with arguments:
var page = require('webpage').create(),
system = require('system'),
proxy, apikey, address;
proxy = system.args[1];
apikey = system.args[2];
address = system.args[3];
page.setProxy(proxy);
page.customHeaders={'Proxy-Authorization': 'Basic '+btoa(apikey)};
page.open(address, function (status) {
page.evaluate(function(){});
console.log(page.content);
phantom.exit();
});
to run use:
phantomjs myscript.js '<http or https>://proxy.zyte.com' '<APIKEY>:' 'http://httpbin.org/ip' // Make sure to include ':' at the end
add '--ignore-ssl-errors=true' when making HTTPS request.
CasperJS
Using Smart Proxy Manager in Phantom object:
var casper = require('casper').create(); casper.start(); phantom.setProxy('proxy.zyte.com','8011', 'http'); // change to https when making HTTPS requests and port to 8014 casper.open('https://httpbin.org/ip', { headers: { 'Proxy-Authorization': 'Basic '+btoa('APIKEY:') // Make sure to include ':' at the end }}).then(function(response) { this.echo(this.getHTML()); }); casper.run();
to run use:
casperjs myscript.js
add '--ignore-ssl-errors=true' when making HTTPS request.