Advertisement
maaveran

phantomjs

Jun 3rd, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. var system = require('system');
  2. var os = system.os;
  3.  
  4. console.log(os.name);
  5.  
  6. var args = system.args;
  7. var name = args[1]
  8. var url = args[2];
  9.  
  10. var page = require('webpage').create();
  11.  
  12. phantom.onError = function(msg,trace){
  13. var msgStack = ['PHANTOM ERROR : '+ msg];
  14.  
  15. if(trace && trace.length){
  16. msgStack.push('TRACE:');
  17. trace.forEach(function(t){
  18. msgStack.push(' -> ' + (t.file || t.sourceURL) + ': ' + t.line + (t.fail));
  19. });
  20. }
  21.  
  22. console.log(msgStack.join('\n'));
  23. phantom.exit(1);
  24. }
  25.  
  26. if(args.length < 2){
  27. throw new Error('Name argument is missing');
  28. }
  29.  
  30. page.viewportSize = { width : 1920 , height :1080};
  31. var postBody = 'username:fasalirr@gmail.com&password:fasal123';
  32. page.customHeaders = {
  33. "Authorization" : "Basic ZmFzYWxpcnJAZ21haWwuY29tOmZhc2FsMTIz"
  34. };
  35.  
  36. page.open(url, 'POST',postBody, function (status){
  37. console.log('**************************************');
  38. console.log(status);
  39. var cookies = page.cookies;
  40. var addCookie;
  41.  
  42. console.log('Listing cookies:');
  43. for(var i in cookies) {
  44. console.log(cookies[i].name + '=' + cookies[i].value + cookies[i].domain+cookies[i].path+cookies[i].httponly+cookies[i].secure);
  45. }
  46.  
  47. var addCookie = phantom.addCookie({
  48. 'name' : cookies[i].name, /* required property */
  49. 'value' : cookies[i].value, /* required property */
  50. 'domain' : cookies[i].domain,
  51. 'path' : cookies[i].path,
  52. 'httponly' : cookies[i].httponly,
  53. 'secure' : cookies[i].secure
  54. });
  55.  
  56.  
  57. // page.open("http://api.staging.etobee.com/", function(statusData){
  58. // console.log(statusData);
  59. // var content = page.content;
  60. // console.log(content);
  61. // })
  62. //
  63. //console.log('Opened '+ url + 'with status: '+ status);
  64.  
  65. page.render('image.jpeg',{format : 'jpeg', quality : '100'});
  66.  
  67. phantom.exit();
  68. });
  69. var test = phantom.cookiesEnabled{true};
  70. console.log(test);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement