medialab/artoo

how to inject artoojs to be used in casperjs

stephencheng opened this issue · 2 comments

Hi

I'd like to use artoo to be used in casperjs (or phantom js) to scrape information. I am able to inject other script and tested ok with it, but have no idea which script I should inject or how to inject in casperjs.

I have got code here:

var casper = require('casper').create();
casper.start("http://mikeyaworski.com/IP", function() {

    // casper.page.injectJs('js/jquery.min.js'); note this one works, i am able to get ip
    // casper.page.injectJs('chrome/content.js'); this one is the one used by chrome extension, not work in this case
    casper.page.injectJs('./artoo_inject.js'); // this one is the bookmarklet I copied to a local file and change the reference of latest.min.js(also saved to local), it does not work for this case
    var ip = this.evaluate(function() {
    var $ = artoo.$;
        return $('#ip').text();
        // return artoo.$('#ip').text();
    });

    this.echo("\nYour public IP address is: " + ip);
});

casper.run();

It doesn't print out the ip but just a null value, I don't know how to debug it. Please can someone from the team give me some advice.

Thanks very much!

some thing to add up. i managed to get true value from

     return artoo._enabled

but any of below will just return null value:

return $('#ip').text();
return artoo.$('#ip').text();

I was thinking if this is because that the there are quite a few artoo scripts, like artoo.*.js, when inject the artoo.js, it can't actually reference to all linked other scripts, in this case, is there a way to just compile all the scripts to one big file?

Hello @stephencheng. It is possible indeed to compile the scripts in one big file. Just take a look at the gulpfile to see what can be done. Concerning the injection, you should take a look at how I do it when using phantomJS here.