call python selenium from php -
i have python script scraping selenium. when call script terminal
/usr/bin/python3 /home/scraping.py
i have no problem scraping work
went try call same script php not working .
on python script have
import sys 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 delete 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 put juste print('test')
i work
for php file y tried
but nothing works
i change permission file chmod 777 scraping.py
in tried change group file www-data
tried put www-data soduers file
in php code have tri
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 problem
the problem log file generate phantomjs , and shebang top in code this
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import sys 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 permission of ghostdriver.log www-data can read id have error again put group www-data in sudoers file no passwd
Comments
Post a Comment