Selenium webdriver + PhantomJS进程没有关闭

时间:2014-11-11 15:34:13

标签: python selenium-webdriver phantomjs

这里只是关于你可以用webdriver和幻像做的最简单的打开和关闭: from selenium import webdriver crawler = webdriver.PhantomJS() crawler.set_window_size(1024,768) crawler.get('https://www.google.com/') crawler.quit()

在Windows(7)上,每次运行我的代码来测试时,conhost.exe和phantomjs.exe进程的新实例都会开始,永不退出。我在这里做些蠢事吗?我认为当crawler.quit()做了......

时,进程会退出

2 个答案:

答案 0 :(得分:0)

去图。重启时解决了问题。

答案 1 :(得分:0)

重新启动不是此问题的解决方案。我在LINUX系统中试验过这个hack。尝试修改service.py

中定义的def stop(self): """ Cleans up the process """ if self._log: self._log.close() self._log = None #If its dead dont worry if self.process is None: return #Tell the Server to properly die in case try: if self.process: self.process.stdin.close() #self.process.kill() self.process.send_signal(signal.SIGTERM) self.process.wait() self.process = None except OSError: # kill may not be available under windows environment pass 函数
send_signal

明确添加行import signal以提供退出phantomjs进程的信号。不要忘记在此文件的开头添加o2 := bson.M{ "$project":bson.M{"_id":1,"title":1,"postdatetime":1,"status":1"answer":bson.M{ "$filter":bson.M{"input":"$answer","as":"ans","cond":bson.M{"$eq":[]string{"$$ans.status","Active",},},},},},} 语句。