在Python中执行Firefox命令

在Python中执行Firefox命令,firefox,python-2.7,command-line,subprocess,Firefox,Python 2.7,Command Line,Subprocess,我到处都读到过,子流程模块是从Python使用命令行的最佳方式,但我很难让它正常工作。我有一个名为PageSaver的firefox扩展,可以保存整个网页的图像。在命令行上,此命令成功保存图像: firefox -savepng "http://www.google.com" 我已尝试使用此脚本自动执行此过程,但没有成功: import subprocess subprocess.call(['firefox', '-savepng', 'http://www.google.com'], sh

我到处都读到过,子流程模块是从Python使用命令行的最佳方式,但我很难让它正常工作。我有一个名为PageSaver的firefox扩展,可以保存整个网页的图像。在命令行上,此命令成功保存图像:

firefox -savepng "http://www.google.com"
我已尝试使用此脚本自动执行此过程,但没有成功:

import subprocess
subprocess.call(['firefox', '-savepng', 'http://www.google.com'], shell=False)
我得到这个错误:

Traceback (most recent call last):
  File "C:/Users/computer_4/Desktop/Scripts/crescentsaver.py", line 2, in <module>
    subprocess.call(['firefox', '-savepng', 'http://www.google.com'], shell=False)
  File "C:\Python27\lib\subprocess.py", line 524, in call
    return Popen(*popenargs, **kwargs).wait()
  File "C:\Python27\lib\subprocess.py", line 711, in __init__
    errread, errwrite)
  File "C:\Python27\lib\subprocess.py", line 948, in _execute_child
    startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
我无法回答自己的问题,因为限制新用户在发布后八小时内回答自己的问题。

subprocess.call()告诉您的错误是它无法在您的
路径上找到firefox命令。(这是Windows搜索命令的目录列表)

这里有两个选项:

  • 在脚本中指定Firefox命令的完整路径:这很简单,只需将完整路径放入python代码中即可
  • 将包含Firefox命令的目录添加到您的路径中。这有点复杂,但是你可以找到一个关于
  • import subprocess
    subprocess.call('firefox -savepng http://www.google.com', shell=True)