python - 如何正确停止 phantomjs 执行

标签 python macos selenium selenium-webdriver phantomjs

我使用以下代码在 Python 中启动并关闭 phantomjs

from selenium import webdriver    
driver = webdriver.PhantomJS()
driver.get(url)
html_doc = driver.page_source
driver.close()

在脚本结束执行后,我仍然在我的 Mac 事件监视器中找到 phantomjs 的实例。实际上,每次我运行脚本时,都会创建一个新进程 phantomjs

我应该如何关闭驱动程序?

最佳答案

截至 2016 年 7 月,driver.close()driver.quit() 对我来说还不够。这杀死了 node 进程,但没有杀死它产生的 phantomjs 子进程。

this GitHub issue 的讨论之后,对我有用的单一解决方案是运行:

import signal

driver.service.process.send_signal(signal.SIGTERM) # kill the specific phantomjs child proc
driver.quit()                                      # quit the node proc

关于python - 如何正确停止 phantomjs 执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25110624/

相关文章:

python - FlickrApi 异常 : Photo not found on calling photo. getSizes()

python - SQL/ python : Transform data from csv and into table with different schema with condition

ios - 找不到“UIKit/UIUserActivity.h”文件,Xcode 9.4

macos - 无法在 Mac 上测试 Mosquitto 服务器

c# - 如何使用 C# 在 Selenium 中迭代 <ul> 的子元素

python - PyPDF2:复制 PDF 会产生空白页

Python/Dictionary/List/Mongo 插入问题-初学者

c++ - 如何在 macOS 中使用(链接)调试版本的 libc++?

java - Selenium - IE 11 中的 NoSuchWindowException

java - Selenium RC 中 isElementPresent 和 isVisible 的区别