mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
3.2.14修复切换模式时cookies问题;改进iframe不稳定等待
This commit is contained in:
parent
ad7f871e8e
commit
c2a29dc066
@ -922,13 +922,14 @@ class ChromiumBaseSetter(object):
|
||||
cookies = cookies_to_tuple(cookies)
|
||||
result_cookies = []
|
||||
for cookie in cookies:
|
||||
if not cookie.get('domain', None):
|
||||
if cookie.get('domain', None) is None:
|
||||
netloc = urlparse(self._page.url).netloc
|
||||
if netloc.replace('.', '').isdigit(): # ip
|
||||
cookie['domain'] = netloc
|
||||
else: # 域名
|
||||
u = netloc.split('.')
|
||||
cookie['domain'] = f'.{u[-2]}.{u[-1]}' if len(u) > 1 else netloc
|
||||
|
||||
result_cookies.append({'value': '' if cookie['value'] is None else cookie['value'],
|
||||
'name': cookie['name'],
|
||||
'domain': cookie['domain']})
|
||||
|
@ -129,9 +129,21 @@ class ChromiumFrame(ChromiumBase):
|
||||
self._is_loading = False
|
||||
self._is_reading = False
|
||||
|
||||
def _onFrameNavigated(self, **kwargs):
|
||||
"""页面跳转时触发"""
|
||||
if kwargs['frame']['frameId'] == self.frame_id and self._first_run is False and self._is_loading:
|
||||
self._is_loading = True
|
||||
|
||||
if self._debug:
|
||||
print('navigated')
|
||||
if self._debug_recorder:
|
||||
self._debug_recorder.add_data((perf_counter(), '加载流程', 'navigated'))
|
||||
|
||||
def _onLoadEventFired(self, **kwargs):
|
||||
"""在页面刷新、变化后重新读取页面内容"""
|
||||
# 用于覆盖父类方法,不能删
|
||||
self._get_new_document()
|
||||
|
||||
if self._debug:
|
||||
print('loadEventFired')
|
||||
if self._debug_recorder:
|
||||
|
@ -108,10 +108,8 @@ class WebPageTab(SessionPage, ChromiumTab):
|
||||
|
||||
@property
|
||||
def cookies(self):
|
||||
if self._mode == 's':
|
||||
return super().get_cookies()
|
||||
elif self._mode == 'd':
|
||||
return super(SessionPage, self).get_cookies()
|
||||
"""以dict方式返回cookies"""
|
||||
return super().cookies
|
||||
|
||||
@property
|
||||
def session(self):
|
||||
@ -282,7 +280,7 @@ class WebPageTab(SessionPage, ChromiumTab):
|
||||
selenium_user_agent = self.run_cdp('Runtime.evaluate', expression='navigator.userAgent;')['result']['value']
|
||||
self.session.headers.update({"User-Agent": selenium_user_agent})
|
||||
|
||||
self.set.cookies(self._get_driver_cookies(as_dict=False, all_info=False), set_session=True)
|
||||
self.set.cookies(self._get_driver_cookies(as_dict=True, all_info=False), set_session=True)
|
||||
|
||||
def cookies_to_browser(self):
|
||||
"""把session对象的cookies复制到浏览器"""
|
||||
@ -294,7 +292,7 @@ class WebPageTab(SessionPage, ChromiumTab):
|
||||
domain = f'.{u[-2]}.{u[-1]}' if len(u) > 1 else netloc
|
||||
cookies = []
|
||||
for cookie in super().get_cookies():
|
||||
if not cookie.get('domain', None):
|
||||
if cookie.get('domain', None) is None:
|
||||
cookie['domain'] = domain
|
||||
|
||||
if domain in cookie['domain']:
|
||||
|
@ -57,7 +57,7 @@ class WebPageTab(SessionPage, ChromiumTab):
|
||||
def mode(self) -> str: ...
|
||||
|
||||
@property
|
||||
def cookies(self) -> Union[dict, list]: ...
|
||||
def cookies(self) -> dict: ...
|
||||
|
||||
@property
|
||||
def session(self) -> Session: ...
|
||||
|
@ -266,7 +266,7 @@ class Drission(object):
|
||||
except AttributeError:
|
||||
browser_domain = ''
|
||||
|
||||
if not cookie.get('domain', None):
|
||||
if cookie.get('domain', None) is None:
|
||||
if browser_domain:
|
||||
if browser_domain.replace('.', '').isdigit(): # ip
|
||||
cookie_domain = browser_domain
|
||||
|
@ -177,10 +177,8 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
|
||||
|
||||
@property
|
||||
def cookies(self):
|
||||
if self._mode == 's':
|
||||
return super().get_cookies()
|
||||
elif self._mode == 'd':
|
||||
return super(SessionPage, self).get_cookies()
|
||||
"""以dict方式返回cookies"""
|
||||
return super().cookies
|
||||
|
||||
@property
|
||||
def session(self):
|
||||
@ -356,7 +354,7 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
|
||||
selenium_user_agent = self.run_cdp('Runtime.evaluate', expression='navigator.userAgent;')['result']['value']
|
||||
self.session.headers.update({"User-Agent": selenium_user_agent})
|
||||
|
||||
self.set.cookies(self._get_driver_cookies(as_dict=False, all_info=False), set_session=True)
|
||||
self.set.cookies(self._get_driver_cookies(as_dict=True), set_session=True)
|
||||
|
||||
def cookies_to_browser(self):
|
||||
"""把session对象的cookies复制到浏览器"""
|
||||
@ -368,7 +366,7 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
|
||||
domain = f'.{u[-2]}.{u[-1]}' if len(u) > 1 else netloc
|
||||
cookies = []
|
||||
for cookie in super().get_cookies():
|
||||
if not cookie.get('domain', None):
|
||||
if cookie.get('domain', None) is None:
|
||||
cookie['domain'] = domain
|
||||
|
||||
if domain in cookie['domain']:
|
||||
@ -460,7 +458,7 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
|
||||
self._has_driver = None
|
||||
|
||||
# ---------------准备废弃---------------
|
||||
def set_cookies(self, cookies, set_session=False, set_driver=False):
|
||||
def set_cookies(self, cookies, set_session=True, set_driver=True):
|
||||
"""添加cookies信息到浏览器或session对象
|
||||
:param cookies: 可以接收`CookieJar`、`list`、`tuple`、`str`、`dict`格式的`cookies`
|
||||
:param set_session: 是否设置到Session对象
|
||||
|
@ -62,7 +62,7 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
|
||||
def mode(self) -> str: ...
|
||||
|
||||
@property
|
||||
def cookies(self) -> Union[dict, list]: ...
|
||||
def cookies(self) -> dict: ...
|
||||
|
||||
@property
|
||||
def session(self) -> Session: ...
|
||||
|
2
setup.py
2
setup.py
@ -6,7 +6,7 @@ with open("README.md", "r", encoding='utf-8') as fh:
|
||||
|
||||
setup(
|
||||
name="DrissionPage",
|
||||
version="3.2.13",
|
||||
version="3.2.14",
|
||||
author="g1879",
|
||||
author_email="g1879@qq.com",
|
||||
description="Python based web automation tool. It can control the browser and send and receive data packets.",
|
||||
|
Loading…
x
Reference in New Issue
Block a user