在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Python/ selenium PhantomJS 調用driver.quit()時出錯

selenium PhantomJS 調用driver.quit()時出錯

dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap['phantomjs.page.settings.userAgent'] = getRandomUserAgent()
print dcap['phantomjs.page.settings.userAgent']
driver = webdriver.PhantomJS(executable_path=phantomJS_path,     desired_capabilities=dcap)
driver.get(url+str(company.companyId))
driver.quit()

錯誤日志如下:

Traceback (most recent call last):
  File "crawler/get_detail.py", line 47, in <module>
    get_detail(company)
  File "crawler/get_detail.py", line 30, in get_detail
    driver.quit()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/phantomjs/webdriver.py", line 76, in quit
    self.service.stop()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.py", line 149, in stop
    self.send_remote_shutdown_command()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/phantomjs/service.py", line 67, in send_remote_shutdown_command
    os.close(self._cookie_temp_file_handle)
OSError: [Errno 9] Bad file descriptor

求關閉driver的正確姿勢

回答
編輯回答
葬憶

driver.quit()

2017年7月24日 22:04
編輯回答
笨笨噠

試試這個

import signal

driver = webdriver.PhantomJS(executable_path=phantomJS_path,     desired_capabilities=dcap)
driver.get(url+str(company.companyId))
driver.service.process.send_signal(signal.SIGTERM)
driver.quit()
2017年3月3日 00:12