1

I want to fetch some information from a website using the phantomjs/casperjs libraries, as I'm looking for the HTML result after all javascripts on a site are run. I worked it out with the following code from this answer:

var page = require('webpage').create();  
page.open('http://www.scorespro.com/basketball/', function (status) {
    if (status !== 'success') {
        console.log('Unable to access network');
    } else {
        var p = page.evaluate(function () {
            return document.getElementsByTagName('html')[0].innerHTML
        });
        console.log(p);
    }
    phantom.exit();
});

And I also worked it out to get phantomjs/casperjs running on heroku by following these instructions, so when I now say heroku run phantomjs theScriptAbove.js on OS X terminal I get the HTML of the given basketball scores website as I was expecting.

But what I actually want is to get the html text from within a Mac desktop application, this is the reason why I was looking for a way to run the scripts on a web server like heroku. So, my question is:

Is there any way to get the HTML text (that my script prints as a result) remotely within my Objective-C desktop application?

Or asked in another way: how can I run and get the answer of my script remotely by using POST/GET?

p.s. I can handle with Rails applications, so if there's a way to do this using Rails - I just need the basic idea of what I have to do and how to get the phantomjs script to communicate with Rails. But I think there might be an even simpler solution ...

Community
  • 1
  • 1
CGee
  • 1,650
  • 5
  • 20
  • 31

1 Answers1

1

If I understand you correctly you're talking about interprocess communication - so that Phantom's result (the page HTML) can somehow be retrieved by the app.

per the phantom docs, couple options:

  • write the HTML to a file and pick up the file in your app
  • run the webserver module and do a GET to phantom, and have the phantom script respond with the page HTML

see http://phantomjs.org/api/webserver/

Artjom B.
  • 61,146
  • 24
  • 125
  • 222