【发布时间】:2016-05-11 18:14:18
【问题描述】:
正在编写 CasperJS 教程,但我的语法出现错误。使用 Python 3.5.1。
文件:scrape.py
import os
import subprocess
APP_ROOT = os.path.dirname(os.path.realpath(__file__))
CASPER = '/projects/casperjs/bin/casperjs'
SCRIPT = os.path.join(APP_ROOT, 'test.js')
params = CASPER + ' ' + SCRIPT
print subprocess.check_output(params, shell=True)
错误:
File "scrape.py", line 10
print subprocess.check_output(params, shell=True)
^
SyntaxError: invalid syntax
YouTube 视频教程:Learning to Scrape...
【问题讨论】:
-
不相关:1-如果
APP_ROOT中有空格;check_output()调用可能会失败,因为CASPER + ' ' + SCRIPT不是应该创建命令行的方式。看来,这里不需要 shell 2- 如果要显示输出;你不需要捕捉它:check_call([CASPER, SCRIPT])3-未成年人:你可以useget_script_dir()instead of__file__
标签: python python-3.x subprocess casperjs