javascript - Using nodeJS and phantomJS to return network requests and responses, only working in console -


I am trying to replicate the phantomJS functionality, only in nods I am using it as a bridge

Generally, it uses the phantomjs netlog.js http://www.google.com/ in the command line without any unwise Will be played. This will return all the Jason's requests and reactions back to all.

What I am doing here is trying to run the code using Code netlog.js phantomjs-node module ( Ignore the line var page = Required ('webpage'). Create () netlog.js .

While the code does not break, What is wrong here? Do I need to pipe a page request?

In app .js :

  var phantom = need ('phantom'); siteUrl = "http://www.google.com/" phantom .create (function (PH) {Ph.create page (function) {var system = required ("system"), address; page.open (siteUrl, function) {// console.log ("open" + siteUrl + "\ N", position + "\ n"); page.evaluate (function () {if (system.args.length === 1) {console.log ('Usage: netlog.js & lt; Gt; '); phantom.exit (1);} and {console.log (system.args [1]) address = system.args [1]; page.onResourceRequested = function (rik) {console.log (' request Done: '+ JSON.stringify (Rick, undefined, 4)); }; Page.onResourceReceived = function (res) {console.log ('received:' + JSON.stringify (res, undefined, 4)); }; Page.open (address, work (status) {if (position! == 'success') {console.log ('failed to load address)';} phantom.exit ();}); }}, Function end (result) {PHP.exit (); }, ThirdLayerLinks); }); }); }, {DnodeOpts: {weak: wrong}});    

You made a mistake during copy-paste. Anyone page Evaluate should not be a call and should not be a single page.open call. You have taken a little more than the basic phatcom-node code.

Fantmos and nodes JS has separate runtime and very different modules. There is no phantom context, as well as the system in the node you probably mean process .

Then the following says:

The callback can not be set directly, instead of using the use page set ('callback', callback)

Fixed code:

  var phantom = require ('phantom'); Var address = "http://google.com/"; Phantom.create (function (pH) {PHP.createPage (function (page) {page.set ("onResourceRequested", function (req) {console.log ('requested:' + JSON.stringify (req, undefined, 4));});) .set ("On Resource Receiver", Function (ridge) {console.log ('Received:' + JSON.stringify (race, undefined, 4)););) Open address (function, status) {if! Status! == 'success') {console.log ('failed to load address)'}}. Phyxt ();}}}})}}, {dnodeOpts : {Weak: wrong}});    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -