3.2.3cookies_to_driver()改名为cookies_to_browser()

This commit is contained in:
g1879 2023-02-25 01:06:46 +08:00
parent 3612fe13e7
commit 6e5c16fee6
5 changed files with 14 additions and 8 deletions

View File

@ -64,7 +64,10 @@ class ChromiumBase(BasePage):
self._chromium_init()
if not tab_id:
json = self._control_session.get(f'http://{self.address}/json').json()
tab_id = [i['id'] for i in json if i['type'] == 'page'][0]
tab_id = [i['id'] for i in json if i['type'] == 'page']
if not tab_id:
raise ConnectionError('连接浏览器失败。')
tab_id = tab_id[0]
self._driver_init(tab_id)
self._get_document()
self._first_run = False

View File

@ -81,7 +81,10 @@ class ChromiumPage(ChromiumBase):
self.process = connect_browser(self._driver_options)[1]
if not tab_id:
json = self._control_session.get(f'http://{self.address}/json').json()
tab_id = [i['id'] for i in json if i['type'] == 'page'][0]
tab_id = [i['id'] for i in json if i['type'] == 'page']
if not tab_id:
raise ConnectionError('连接浏览器失败。')
tab_id = tab_id[0]
self._driver_init(tab_id)
self._get_document()
@ -398,7 +401,7 @@ class ChromiumTabRect(object):
@property
def browser_location(self):
"""返回浏览器在屏幕上的坐标"""
"""返回浏览器在屏幕上的坐标,左上角为(0, 0)"""
r = self._get_browser_rect()
if r['windowState'] in ('maximized', 'fullscreen'):
return 0, 0

View File

@ -36,7 +36,7 @@ def configs_to_here(save_name=None):
:return: None
"""
om = OptionsManager('default')
save_name = str(save_name) if save_name is not None else 'dp_configs.ini'
save_name = f'{save_name}.ini' if save_name is not None else 'dp_configs.ini'
om.save(save_name)

View File

@ -326,7 +326,7 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
if self._session_url:
if copy_cookies:
self.cookies_to_driver()
self.cookies_to_browser()
if go:
self.get(self._session_url)
@ -356,8 +356,8 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
self.set.cookies(self._get_driver_cookies(as_dict=True), set_session=True)
def cookies_to_driver(self):
"""把session对象的cookies复制到driver对象"""
def cookies_to_browser(self):
"""把session对象的cookies复制到浏览器"""
ex_url = extract(self._session_url)
domain = f'{ex_url.domain}.{ex_url.suffix}'
cookies = []

View File

@ -118,7 +118,7 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
def cookies_to_session(self, copy_user_agent: bool = True) -> None: ...
def cookies_to_driver(self) -> None: ...
def cookies_to_browser(self) -> None: ...
def get_cookies(self, as_dict: bool = False, all_domains: bool = False) -> Union[dict, list]: ...