python+selenium+phantomjs中经常会出现phantomjs占cpu过高的情况,怎么办?

用途:爬虫(框架:scrapy)

            cap = dict(DesiredCapabilities.PHANTOMJS)
            cap["phantomjs.page.settings.resourceTimeout"] = 1000
            cap["phantomjs.page.settings.loadImages"] = False
            cap["phantomjs.page.settings.webSecurityEnabled"] = False
            driver = webdriver.PhantomJS(executable_path='/usr/local/bin/phantomjs',desired_capabilities=cap)
            driver.set_page_load_timeout(20)
            driver.set_script_timeout(20)
            
            try:
               driver.get(request.url)

            except Exception as e:
               print e
            finally:
               driver.quit()
               
发现phantomjs经常quit不掉,以致cpu越来越高,pgrep phantomjs,phantomjs一大堆。
个人认为,driver.get(request.url),一旦遇到js的坑,就会死在这儿,从而phantomjs也就无法quit。
请问大家有无好办法?
阅读 3k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进