How do I set proxy in phantomjs

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

They didn't update their docs.


As for as phantom 2.0.10 version the following code is running very well in my windows machine

  phantom.create(["--proxy=201.172.242.184:15124", "--proxy-type=socks5"])
      .then((instance) => {
          phInstance = instance;
          return instance.createPage();
      })
      .then((page) => {
          sitepage = page;
          return page.open('http://newsdaily.online');
      })
      .then((status) => {
          console.log(status);
          return sitepage.property('title');
      })
      .then((content) => {
          console.log(content);
          sitepage.close();
          phInstance.exit();
      })
      .catch((error) => {
          console.log(error);
          phInstance.exit();
      });

As a side effect of trying to figure out an issue on Github for phantomjs-nodejs I was able to set a proxy as follows:

phantom = require 'phantom'
parameters = {
    loadimages: '--load-images=no',
    websecurity: '--web-security=no',
    ignoresslerrors: '--ignore-ssl-errors=yes',
    proxy: '--proxy=10.0.1.235:8118',
}
urls = {
    checktor: "https://check.torproject.org/",
    google: "https://google.com",
}
        
phantom.create parameters.websecurity, parameters.proxy, (ph) ->
  ph.createPage (page) ->
    page.open urls.checktor, (status) ->
      console.log "page opened? ", status
      page.evaluate (-> document.title), (result) ->
        console.log 'Page title is ' + result
        ph.exit()

The result where the proxy uses Tor was:

page opened? success

Page title is Congratulations. This browser is configured to use Tor.


Time is going on, so PhantomJS now able to set proxy "on the fly" (even on per-page-basis): see this commit: https://github.com/ariya/phantomjs/commit/efd8dedfb574c15ddaac26ae72690fc2031e6749

Here is sample usage of new setProxy function (i did not find web page setting usage, this is general usage of proxy on instance of phantom):

https://github.com/ariya/phantomjs/blob/master/examples/openurlwithproxy.js

If you want per-page proxy, use full URL for proxy (schema, user name,password, host, port - all it the URL)