【问题标题】:python phanthomjs is not working with nohuppython phanthomjs 不适用于 nohup
【发布时间】:2017-01-16 00:47:28
【问题描述】:

我正在使用 phanthomjs 运行 selenium,如果我触发它时脚本运行完美:

python my_script.py 

但是当我尝试使用 nohup 时:

nohup python my_script.py &

我收到以下错误:

selenium.common.exceptions.WebDriverException: Message: Service phantomjs unexpectedly exited. Status code was: 8

【问题讨论】:

  • 在 screen 或 tmux 中运行怎么样?

标签: python selenium phantomjs


【解决方案1】:

可能为时已晚,但我刚刚使用另一个代码遇到了类似的错误,我找到了解决方案。所以,当你运行 nohup 时,你的程序的输出会被重定向到 nohup.out,而我的文件是这样的:

Traceback (most recent call last):
me/fanar/.local/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 109, in assert_process_still_running

  File "main.py", line 51, in <module>
    Work()
  File "main.py", line 41, in Work
    TakeImage() # start o 16
  File "main.py", line 9, in TakeImage
    driver = webdriver.PhantomJS()
  File "/home/fanar/.local/lib/python2.7/site-packages/selenium/webdriver/phantomjs/webdriver.py", line 52, in __init__
    self.service.start()
  File "/home/fanar/.local/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 96, in start
    self.assert_process_still_running()
  File "/home/fanar/.local/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 109, in assert_process_still_running
    % (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service phantomjs unexpectedly exited. Status code was: 1

解决方法是去

.local/lib/python2.7/site-packages/selenium/webdriver/common/service.py

并注释掉一行

self.assert_process_still_running()

【讨论】:

    【解决方案2】:

    指定参数对我有用:

    driver = webdriver.PhantomJS(executable_path = '/usr/lib/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-20
      • 1970-01-01
      • 2021-03-11
      • 2016-04-26
      • 2022-11-26
      • 1970-01-01
      • 2015-05-28
      相关资源
      最近更新 更多