I have a python script for scraping with selenium. When i call my script with terminal like this
/usr/bin/python3 /home/scraping.py
i have no problem my scraping work
Went a try to call the same script with php is not working .
on my python script a have this
import sys
from selenium import webdriver
driver =webdriver.PhantomJS(executable_path='/usr/local/bin/phantomjs')
driver.set_window_size(1024, 768)
driver.get(url)
page = driver.page_source.encode("utf-8")
print(page)
when i delete this line
driver =webdriver.PhantomJS(executable_path='/usr/local/bin/phantomjs')
driver.set_window_size(1024, 768)
driver.get(url)
page = driver.page_source.encode("utf-8")
in i put juste print('test')
i this work
for my php file y tried
Running a Python script from PHP
Execute Python script from Php
How to call a Python Script from PHP?
but nothing works
i change my permission file to chmod 777 scraping.py
in tried to change group file for www-data
i tried to put www-data to soduers file
in my php code i have tri this
output = array();
exec("/usr/bin/python3 /home/scraping.py",$output);
var_dump( $output);
$command = escapeshellcmd('/usr/bin/python3 /home/scraping.py');
$output = shell_exec($command);
echo $output;
ob_start();
passthru('/usr/bin/python3 /home/scraping.py');
$output =ob_get_clean()
EDIT
I have found my problem
The problem is the log file generate by phantomjs and and shebang to top in my code like this
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
from selenium import webdriver
driver =webdriver.PhantomJS( service_log_path='/home/ghostdriver.log'executable_path='/usr/local/bin/phantomjs')
driver.set_window_size(1024, 768)
driver.get(url)
page = driver.page_source.encode("utf-8")
print(page)
and after change the permission of the ghostdriver.log for the www-data can read id you have a error again put the group www-data in the sudoers file with no passwd