修复set_flags的一个问题;修改quit()逻辑

This commit is contained in:
g1879 2024-03-12 23:41:45 +08:00
parent 2157fcf9e3
commit 4a9ef7d6b2
6 changed files with 27 additions and 20 deletions

View File

@ -203,24 +203,31 @@ class Browser(object):
:param force: 是否立刻强制终止进程 :param force: 是否立刻强制终止进程
:return: None :return: None
""" """
pids = [pid['id'] for pid in self.run_cdp('SystemInfo.getProcessInfo')['processInfo']] try:
for tab in self._all_drivers.values(): self.run_cdp('Browser.close')
except PageDisconnectedError:
pass
self.driver.stop()
drivers = list(self._all_drivers.values())
for tab in drivers:
for driver in tab: for driver in tab:
driver.stop() driver.stop()
if force: if not force:
from psutil import Process return
for pid in pids:
try: try:
Process(pid).kill() pids = [pid['id'] for pid in self.run_cdp('SystemInfo.getProcessInfo')['processInfo']]
except: except:
pass return
else:
from psutil import Process
for pid in pids:
try: try:
self.run_cdp('Browser.close') Process(pid).kill()
self.driver.stop() except:
except PageDisconnectedError: pass
self.driver.stop()
from os import popen from os import popen
from platform import system from platform import system

View File

@ -176,8 +176,8 @@ def set_flags(opt):
states_dict = load(f) states_dict = load(f)
except JSONDecodeError: except JSONDecodeError:
states_dict = {} states_dict = {}
flags_list = [] if opt.clear_file_flags else states_dict.setdefault( states_dict.setdefault('browser', {}).setdefault('enabled_labs_experiments', [])
'browser', {}).setdefault('enabled_labs_experiments', []) flags_list = [] if opt.clear_file_flags else states_dict['browser']['enabled_labs_experiments']
flags_dict = {} flags_dict = {}
for i in flags_list: for i in flags_list:
f = str(i).split('@', 1) f = str(i).split('@', 1)

View File

@ -474,7 +474,7 @@ class ChromiumBase(BasePage):
def cookies(self, as_dict=False, all_domains=False, all_info=False): def cookies(self, as_dict=False, all_domains=False, all_info=False):
"""返回cookies信息 """返回cookies信息
:param as_dict: 为True时返回由{name: value}键值对组成的dict为True时返回list且all_info无效 :param as_dict: 为True时以dict格式返回为False时返回list且all_info无效
:param all_domains: 是否返回所有域的cookies :param all_domains: 是否返回所有域的cookies
:param all_info: 是否返回所有信息为False时只返回namevaluedomain :param all_info: 是否返回所有信息为False时只返回namevaluedomain
:return: cookies信息 :return: cookies信息

View File

@ -363,7 +363,7 @@ class WebPageTab(SessionPage, ChromiumTab, BasePage):
def cookies(self, as_dict=False, all_domains=False, all_info=False): def cookies(self, as_dict=False, all_domains=False, all_info=False):
"""返回cookies """返回cookies
:param as_dict: 是否以字典方式返回 :param as_dict: 为True时以dict格式返回为False时返回list且all_info无效
:param all_domains: 是否返回所有域的cookies :param all_domains: 是否返回所有域的cookies
:param all_info: 是否返回所有信息False则只返回namevaluedomain :param all_info: 是否返回所有信息False则只返回namevaluedomain
:return: cookies信息 :return: cookies信息

View File

@ -221,7 +221,7 @@ class SessionPage(BasePage):
def cookies(self, as_dict=False, all_domains=False, all_info=False): def cookies(self, as_dict=False, all_domains=False, all_info=False):
"""返回cookies """返回cookies
:param as_dict: 是否以字典方式返回False则以list返回 :param as_dict: 为True时以dict格式返回为False时返回list且all_info无效
:param all_domains: 是否返回所有域的cookies :param all_domains: 是否返回所有域的cookies
:param all_info: 是否返回所有信息False则只返回namevaluedomain :param all_info: 是否返回所有信息False则只返回namevaluedomain
:return: cookies信息 :return: cookies信息

View File

@ -298,7 +298,7 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
def cookies(self, as_dict=False, all_domains=False, all_info=False): def cookies(self, as_dict=False, all_domains=False, all_info=False):
"""返回cookies """返回cookies
:param as_dict: 是否以字典方式返回False以list形式返回 :param as_dict: 为True时以dict格式返回为False时返回list且all_info无效
:param all_domains: 是否返回所有域的cookies :param all_domains: 是否返回所有域的cookies
:param all_info: 是否返回所有信息False则只返回namevaluedomain :param all_info: 是否返回所有信息False则只返回namevaluedomain
:return: cookies信息 :return: cookies信息