{"id":7770,"date":"2015-10-23T20:24:02","date_gmt":"2015-10-23T20:24:02","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2015\/10\/23\/casperjs-passing-data-back-to-php-open-source-projects-n1k0-casperjs\/"},"modified":"2015-10-23T20:24:02","modified_gmt":"2015-10-23T20:24:02","slug":"casperjs-passing-data-back-to-php-open-source-projects-n1k0-casperjs","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2015\/10\/23\/casperjs-passing-data-back-to-php-open-source-projects-n1k0-casperjs\/","title":{"rendered":"CasperJS passing data back to PHP-open source projects n1k0\/casperjs"},"content":{"rendered":"<p><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/04ac8f1c11b048325e334c7ca27078a4?s=128&amp;d=identicon&amp;r=PG\" \/> <strong>Hemerson Varela<\/strong><\/p>\n<p>I think the best way to transfer data from CasperJS to another language such as PHP is running CasperJS script as a service. Because CasperJS has been written over PhantomJS, CasperJS can use an embedded web server module of PhantomJS called Mongoose.<\/p>\n<p>For information about how works the embedded web server see here<\/p>\n<p>Here an example about how a CasperJS script can start a web server.<\/p>\n<pre><code>\/\/define ip and port to web service\nvar ip_server = '127.0.0.1:8585';\n\n\/\/includes web server modules\nvar server = require('webserver').create();\n\n\/\/start web server\nvar service = server.listen(ip_server, function(request, response) {\n\n    var links = [];\n    var casper = require('casper').create();\n\n    function getLinks() {\n        var links = document.querySelectorAll('h3.r a');\n        return Array.prototype.map.call(links, function(e) {\n            return e.getAttribute('href')\n        });\n    }\n\n    casper.start('http:\/\/google.fr\/', function() {\n        \/\/ search for 'casperjs' from google form\n        this.fill('form[action=\"\/search\"]', { q: 'casperjs' }, true);\n    });\n\n    casper.then(function() {\n        \/\/ aggregate results for the 'casperjs' search\n        links = this.evaluate(getLinks);\n        \/\/ now search for 'phantomjs' by filling the form again\n        this.fill('form[action=\"\/search\"]', { q: 'phantomjs' }, true);\n    });\n\n    casper.then(function() {\n        \/\/ aggregate results for the 'phantomjs' search\n        links = links.concat(this.evaluate(getLinks));\n    });\n\n    \/\/\n    casper.run(function() {\n            response.statusCode = 200;\n            \/\/sends results as JSON object\n            response.write(JSON.stringify(links, null, null));\n            response.close();              \n    });\n\n});\nconsole.log('Server running at http:\/\/' + ip_server+'\/');\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Hemerson Varela I think the best way to transfer data from CasperJS to another language such as PHP is running CasperJS script as a service. Because CasperJS has been written over PhantomJS, CasperJS can use an embedded web server module of PhantomJS called Mongoose. For information about how works the embedded web server see here [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7770","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7770","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=7770"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7770\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7770"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7770"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7770"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}