selenium如何避免当代码出现错误,自行停止程序,
导致代码运行不到这句driver.close()关闭浏览器的代码后,出现大量浏览器资源占用linux服务器内存的情况
try:
spider = webdriver.Chrome(path)
spider.get(url)
cookies = spider.get_cookies()
print(f"main: cookies = {cookies}")
spider.delete_all_cookies()
spider.close()
except:
pass
for handle in spider.window_handles: #窗口跳转
spider.switch_to.window(handle)
spider.quit()
try except finally