I have installed phantomjs on my windows 8.1 pc, and i have done some scraping by executing the js file from command prompt. The question now is how do i run phantomjs program in shared hosting. I have looked on the web for a solution and all i could find is "I would suggest moving the PhantomJS binary file to your home directory. Once there, you can execute PhantomJS by simply pointing to the file: ~/phantomjs -v.". But i cant understand what "~/ phantomjs -v" means. Where and how do i write and run this code? to be clear here is the javascript file
var page = new WebPage()
var fs = require('fs');
page.onLoadFinished = function() {
console.log("page load finished");
page.render('export.png');
fs.write('1.html', page.content, 'w');
phantom.exit();
};
page.open("https://url", function() {
page.evaluate(function() {
});
});
Now how do i run this file on my shared hosting (linux 64-bit) and what is "~/ phantomjs -v"?
答案 0 :(得分:1)
~
是用户主目录的快捷方式。
~/phantomjs
就像在"二进制文件中使用名为 phantomjs 的二进制文件,它位于我的主目录"。
要运行scrape,您需要启动PhantomJS并为其提供脚本名称。因此,在您的情况下,您可以将PhantomJS及其脚本放入您的主目录,然后从shell执行此命令:
~/phantomjs ~/script.js
那是"启动我的主目录中的phantomjs并让它运行一个脚本也在我的主目录中#34;。
如果要从另一个脚本(例如PHP脚本)启动此命令,可以在PHP中使用shell_exec
命令。
但要警惕共享托管所施加的限制 - 通常它们会限制执行时间和CPU消耗,这在PhantomJS的情况下可能会非常高。我建议您使用VPS进行此类工作。