mirror of
https://github.com/ariya/phantomjs.git
synced 2024-09-11 04:46:09 +03:00
Example of runtime proxy setup
https://github.com/ariya/phantomjs/issues/10803
This commit is contained in:
parent
9da842df2b
commit
3c5302d567
22
examples/openurlwithproxy.coffee
Normal file
22
examples/openurlwithproxy.coffee
Normal file
@ -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 <proxyHost> <proxyPort> <URL>"
|
||||
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
|
24
examples/openurlwithproxy.js
Normal file
24
examples/openurlwithproxy.js
Normal file
@ -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 <proxyHost> <proxyPort> <URL>');
|
||||
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();
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue
Block a user