CptNemo CptNemo - 7 months ago 146
Python Question

How to properly stop phantomjs execution

I initiated and close

phantomjs
in Python with the following

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


yet after the script ends execution I still find an instance of
phantomjs
in my Mac Activity Monitor. And actually every time I run the script a new process
phantomjs
is created.

How should I close the driver?

Answer

The .close() method is not guaranteed to release all resources associated with a driver instance. Note that these resources include, but may not be limited to, the driver executable (PhantomJS, in this case). The .quit() method is designed to free all resources of a driver, including exiting the executable process.