openurlwithproxy.js 779 B

12345678910111213141516171819202122232425
  1. "use strict";
  2. var page = require('webpage').create(),
  3. system = require('system'),
  4. host, port, address;
  5. if (system.args.length < 4) {
  6. console.log('Usage: openurlwithproxy.js <proxyHost> <proxyPort> <URL>');
  7. phantom.exit(1);
  8. } else {
  9. host = system.args[1];
  10. port = system.args[2];
  11. address = system.args[3];
  12. phantom.setProxy(host, port, 'manual', '', '');
  13. page.open(address, function (status) {
  14. if (status !== 'success') {
  15. console.log('FAIL to load the address "' +
  16. address + '" using proxy "' + host + ':' + port + '"');
  17. } else {
  18. console.log('Page title is ' + page.evaluate(function () {
  19. return document.title;
  20. }));
  21. }
  22. phantom.exit();
  23. });
  24. }