Ben Muircroft Ben Muircroft - 4 months ago 280x
Node.js Question

How do I set proxy in phantomjs

This page says:

You can also pass command line switches to the phantomjs process by specifying additional args to phantom.create(), eg:

phantom.create '--load-images=no', '--local-to-remote-url-access=yes', (page) ->

or by specifying them in the options* object:

phantom.create {parameters: {'load-images': 'no', 'local-to-remote-url-access': 'yes'}}, (page) ->

These examples are only in coffee script and also they insinuate that the create function can take



create([object object],function)

but really the first parameter expected is the function!

I really wanted to try I might have the wrong idea but to me it looks like they can be used in the create function (right before you do the createPage), am I wrong?

I have tried several things, the most logical one is this:

var phantom = require('phantom');
browser.createPage(function(page){'', function() {


So the page gets opened. I know this because I am making req.php save the $_SERVER object to a txt pad but, the REMOTE_ADDR and REMOTE_PORT headers are not the ones in the proxy I have set. They have no effect. I have also tried:


As the docs call that object the options* object *see above^



I have also had a dig through the phantom module to find the create function. It is not written in js I can't see it at least. It must be in C++. It looks like this module has been updated but, the examples deep inside the module look like old code.

How do I do this?


var phantom = require('phantom');

browser.setProxy('','21320','http', null, null, function(){
'', function() {


This produces no error and the page gets scraped but the proxy is ignored.

{ parameters: { 'proxy': 'socks://' } }

They didn't update their docs.