dongxin991209 2016-12-02 06:02
浏览 102

从python到php的有限返回值

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.

  • 写回答

2条回答 默认 最新

  • douting0585 2016-12-02 07:34
    关注

    There can be multiple issues:

    • Different user's (execution permissions for the python script)
    • Fullpath to python interpreter and script ('/usr/bin/python ~/PythonScripts/readable.py')
    • ...

    You could use popen instead of shell_exec, to make debugging easier. That results in numeric return value, stdout and stderr.

    评论

报告相同问题?

悬赏问题

  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题