python 在调用 Phantomjs 时报错

作者:cnchanghai , 分类:编程学习 , 浏览:1161 , 评论:

python 在调用 Phantomjs 对视频网站进行抓取时报错 

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

[root@localhost clog]# python manage.py  getmovie
movielist over
Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/lib64/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "/usr/lib64/python2.7/site-packages/django/core/management/__init__.py", line 356, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib64/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/lib64/python2.7/site-packages/django/core/management/base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "/data/clog/blog/management/commands/getmovie.py", line 21, in handle
    tv=tvshow()
  File "/data/clog/blog/moviebot.py", line 58, in tvshow
    driver = selenium.webdriver.PhantomJS()
  File "/usr/lib/python2.7/site-packages/selenium/webdriver/phantomjs/webdriver.py", line 52, in __init__
    self.service.start()
  File "/usr/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 96, in start
    self.assert_process_still_running()
  File "/usr/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: 127

此为系统中缺少相应的组件导致的。

在centos 中 使用 yum install  /y  fontconfig

在ubuntu中使用  apt-get install libfontconfig

结果如下 

Installed:
  fontconfig.x86_64 0:2.10.95-10.el7                                                                             

Dependency Installed:
  fontpackages-filesystem.noarch 0:1.44-8.el7                                                                    

Complete!
[root@localhost clog]# python manage.py  getmovie
movielist over
tvlist over
movie suggest over
later play over
all over
[root@localhost clog]#

李长海的博客