Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8719785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:52:51+00:00 2026-06-13T06:52:51+00:00

I have a phantomJS script that is executed via an exec() call in a

  • 0

I have a phantomJS script that is executed via an exec() call in a node.js script.
Now I need to return a string from the PhantomJS script so that it can be utilized back in node.
Is there a way to achieve that ?

Node app:

child = exec('./phantomjs dumper.js',
    function (error, stdout, stderr) {
        console.log(stdout, stderr);      // Always empty
    });

dumper.js (Phantom)

var system = require('system');
var page = require('webpage').create();
page.open( system.args[1], function (status) {
    if (status !== 'success') {
        console.log('Unable to access the network!');
    } else {

        return "String"; // Doesn't work
    }
    phantom.exit('String2'); //Doesn't work either
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T06:52:52+00:00Added an answer on June 13, 2026 at 6:52 am

    Yeah just output a JSON string from PhantomJS using JSON.stringify(result) and parse it in node.js with JSON.parse(stdout).

    Like this for example:

    Node.js:

    child = exec('./phantomjs dumper.js',
        function (error, stdout, stderr) {
            console.log(stdout, stderr);      // Always empty
            var result = JSON.parse(stdout);
        }
    );
    

    PhantomJS:

    var system = require('system');
    var page = require('webpage').create();
    page.open( system.args[1], function (status) {
        if (status !== 'success') {
            console.log('Unable to access the network!');
        } else {
    
            console.log(JSON.stringify({string:"This is a string", more: []}));
        }
        phantom.exit();
    });
    

    Here is some boilerplate for how to use PhantomJS to scrape.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a nodejs script that uses phantomjs-node to scrape a webpage. It works
I have a PhantomJS/CasperJS script which I'm running from within a node.js script using
I have Backbone website. I've used phantomjs so that search engines can look up
I've got a script that runs in PhantomJS on my server that I need
I have a PhantomJS script that loads a local HTML file, injects some javascript
I have a data type that is an instance of Monoid so I can
I have a section of a web page that I need to take a
I have a few pure-JavaScript, client-side tests using PhantomJS. These I'd like to integrate
I have a table with links in the header that hide a range of
Whenever I launch the debugger from PyDev it complaints about breakpoints on files that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.