M
M
michellie2018-04-05 21:26:11
PhantomJS
michellie, 2018-04-05 21:26:11

How to debug Phantomjs?

I'm trying to automate the browser on the server.
There were a couple of questions.
It is not clear at all how to develop on it. The script runs and that's it. No errors, no results, nothing. How to get at least some kind of answer and errors from the phantom?

<?php
$output = shell_exec('phantomjs /usr/local/share/phantomjs-2.1.1-linux-x86_64/examples/instagram_reg.js');
echo "<pre>$output</pre>";
?>

"use strict";

var webpage=require('webpage'); 
var fs=require('fs'); 
var system=require('system'); 

var page=webpage.create(); 
var url="https://www.instagram.com"; 

var useragent = [];
useragent.push('Opera/9.80 (X11; Linux x86_64; U; fr) Presto/2.9.168 Version/11.50');
useragent.push('Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25');
useragent.push('Opera/12.02 (Android 4.1; Linux; Opera Mobi/ADR-1111101157; U; en-US) Presto/2.9.201 Version/12.02');


page.settings = { 
  loadImages: false, 
  javascriptEnabled: true, 
  userAgent: useragent[Math.floor(Math.random() * useragent.length)], 
}; 

page.onResourceRequested = function(requestData, request) {
  if ((/http:\/\/.+?\.css$/gi).test(requestData['url'])) {
    request.abort();
  }

page.onError = function (msg, trace) {
    console.log(msg);
    trace.forEach(function (item) {
        console.log('  ', item.file, ':', item.line);
    });
};

var page = require('webpage').create(); 
phantom.cookiesEnabled = false; 

page.open("https://www.instagram.com", function(status) { 

  if (status === "success") { 
   page.injectJs('//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js');
    page.evaluate(function() { 
        $('form div:nth-child(2)').find('input').value = "[email protected]"; 
        $('form div:nth-child(3)').find('input').value = "Merylyn Maccaine";
        $('form div:nth-child(4)').find('input').value = "Michaellir77";
        $('form div:nth-child(5)').find('input').value = "ein4";
        $('form div:nth-child(5)').find('button').click(); 
    }); 
  


window.setTimeout(function() { 
     

    phantom.exit();    
    
    }, 5000); 
     
     
  } 
   
   
   
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
forspamonly2, 2018-04-06
@michellie

the phantom is dead. use headless chrome instead with some puppeteer. and for debugging run chrome with gui.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question