Working on a CasperJS tutorial and I'm getting an error with my syntax. Using Python 3.5.1.
File: 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)
Error:
File "scrape.py", line 10
print subprocess.check_output(params, shell=True)
^
SyntaxError: invalid syntax
YouTube Video tutorial: Learning to Scrape...
APP_ROOThas spaces in it; thecheck_output()call may fail becauseCASPER + ' ' + SCRIPTis not how the command line should be created. It seems, you don't need the shell here 2- if you want to display the output; you don't need to capture it:check_call([CASPER, SCRIPT])3- minor: you could useget_script_dir()instead of__file__