From 3c5302d567ea688cd67a18bfe37ba9eb7794a624 Mon Sep 17 00:00:00 2001 From: Artem Koshelev Date: Wed, 2 Apr 2014 18:33:48 +0400 Subject: [PATCH] Example of runtime proxy setup https://github.com/ariya/phantomjs/issues/10803 --- examples/openurlwithproxy.coffee | 22 ++++++++++++++++++++++ examples/openurlwithproxy.js | 24 ++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 examples/openurlwithproxy.coffee create mode 100644 examples/openurlwithproxy.js diff --git a/examples/openurlwithproxy.coffee b/examples/openurlwithproxy.coffee new file mode 100644 index 00000000..32ec3f52 --- /dev/null +++ b/examples/openurlwithproxy.coffee @@ -0,0 +1,22 @@ +page = require("webpage").create() +system = require("system") +host = undefined +port = undefined +address = undefined +if system.args.length < 4 + console.log "Usage: openurlwithproxy.js " + phantom.exit 1 +else + host = system.args[1] + port = system.args[2] + address = system.args[3] + phantom.setProxy host, port, "manual", "", "" + page.open address, (status) -> + if status isnt "success" + console.log "FAIL to load the address \"" + address + "\" using proxy \"" + host + ":" + port + "\"" + else + console.log "Page title is " + page.evaluate(-> + document.title + ) + phantom.exit() + return diff --git a/examples/openurlwithproxy.js b/examples/openurlwithproxy.js new file mode 100644 index 00000000..d74f1ec4 --- /dev/null +++ b/examples/openurlwithproxy.js @@ -0,0 +1,24 @@ +var page = require('webpage').create(), + system = require('system'), + host, port, address; + +if (system.args.length < 4) { + console.log('Usage: openurlwithproxy.js '); + phantom.exit(1); +} else { + host = system.args[1]; + port = system.args[2]; + address = system.args[3]; + phantom.setProxy(host, port, 'manual', '', ''); + page.open(address, function (status) { + if (status !== 'success') { + console.log('FAIL to load the address "' + + address + '" using proxy "' + host + ':' + port + '"'); + } else { + console.log('Page title is ' + page.evaluate(function () { + return document.title; + })); + } + phantom.exit(); + }); +}