I am calling the python script from php using the following command
$url = "https://www.digitalocean.com/community/tutorials/how-to-secure-your-redis-installation-on-ubuntu-14-04";
$output = shell_exec('python PythonScripts/readable.py '.$url);
echo($output);
When I run the file using commandline
python extractor.py https://www.digitalocean.com/community/tutorials/how-to-secure-your-redis-installation-on-ubuntu-14-04
I am getting the desired output.
The contents of python file are
import sys
from readability.readability import Document
from urllib import FancyURLopener
class MyOpener(FancyURLopener):
version = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1.11)'
myopener = MyOpener()
request = myopener.open(sys.argv[1])
html = request.read()
readable_article = Document(html).summary()
readable_title = Document(html).short_title()
print readable_article #If I use readable_title then it's getting printed in php
The problem is that readable_article
is not captured by php. But when I use command line both readable_article
and readable_title
are printed out.
What can be the issue? I tried with exec(), system()
and still no luck.