我有一個腳本可以在無頭模式下運行 webdriver。我觀察到在整個腳本執行之后,該行程仍在運行。
這是我面臨的問題的模仿。
from selenium import webdriver
from webbrowser import Chrome
from ssl import Options
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
class PythonOrg():
def Setup(self):
self.chrome_options = Options()
self.chrome_options.add_argument("--headless")
# self.driver = webdriver.Chrome(service=Service(ChromeDriverManager().install())) #not a headless
self.driver = webdriver.Chrome(options=self.chrome_options)
def GetLink(self):
driver = self.driver
driver.get('https://www.python.org')
print(driver.title)
driver.close()
print('Closed the driver')
inst = PythonOrg()
inst.Setup()
inst.GetLink()
注意:這只是實際專案中問題的復制。
幫助我了解如何在流程完成后管理流程,我是 Python 平臺的新手。
uj5u.com熱心網友回復:
webdriver 有兩個選項 - quit() 和 close()
# Closes the current window
driver.close()
# All windows related to driver instance will quit
driver.quit()
似乎您只是在關閉視窗,因此實體仍然處于活動狀態。用于quit()終止實體。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/507728.html
