I'm writing a PHP script to scrape external website products. The external website uses JavaScript to render product lists that's why my PHP script was not working to scrape those products.
So, I searched for another solution and found JavaScript libraries like PhantomJS and CasperJS.
I've done all my work on my local server but when I'm unable to run my code on Linux.
Here is what I tried through cPanel terminal:
export PHANTOMJS_EXECUTABLE=/home/saadatas/public_html/wp-content/plugins/product-scraper/includes/phantomjs/bin/phantomjs
And
/home/saadatas/public_html/wp-content/plugins/product-scraper/includes/casperjs/bin/casperjs /home/saadatas/public_html/wp-content/plugins/product-scraper/assets/js/ScrapeCategoryProducts.js
I got the expected result but when I tried the same in my PHP code using shell_exec, it didn't work. Here is the PHP file code.
shell_exec('export PHANTOMJS_EXECUTABLE=/home/saadatas/public_html/wp-content/plugins/product-scraper/includes/phantomjs/bin/phantomjs');
And
exec('/home/saadatas/public_html/wp-content/plugins/product-scraper/includes/casperjs/bin/casperjs /home/saadatas/public_html/wp-content/plugins/product-scraper/assets/js/ScrapeCategoryProducts.js');
NOTE: I also tried adding 2>&1 in the script and I double-checked that the shell_exec command is enabled.
Also, tried using putenv but it didn't work.
putenv("CASPERJS_EXECUTABLE=".SC_PLUGIN_DIR.'includes/casperjs/bin/casperjs');
Let me if you need more detail.
Any help will be appreciated.
Thanks in advance.