mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
page对象增加user_agent属性
This commit is contained in:
parent
d9281914dd
commit
8a0b647b22
@ -335,6 +335,11 @@ class ChromiumBase(BasePage):
|
|||||||
"""返回页面加载策略,有3种:'none'、'normal'、'eager'"""
|
"""返回页面加载策略,有3种:'none'、'normal'、'eager'"""
|
||||||
return self._page_load_strategy
|
return self._page_load_strategy
|
||||||
|
|
||||||
|
@property
|
||||||
|
def user_agent(self):
|
||||||
|
"""返回user agent"""
|
||||||
|
return self.run_cdp('Runtime.evaluate', expression='navigator.userAgent;')['result']['value']
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def scroll(self):
|
def scroll(self):
|
||||||
"""返回用于滚动滚动条的对象"""
|
"""返回用于滚动滚动条的对象"""
|
||||||
|
@ -115,6 +115,9 @@ class ChromiumBase(BasePage):
|
|||||||
@property
|
@property
|
||||||
def page_load_strategy(self) -> str: ...
|
def page_load_strategy(self) -> str: ...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def user_agent(self) -> str: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def scroll(self) -> ChromiumPageScroll: ...
|
def scroll(self) -> ChromiumPageScroll: ...
|
||||||
|
|
||||||
|
@ -124,6 +124,14 @@ class WebPageTab(SessionPage, ChromiumTab):
|
|||||||
"""以dict方式返回cookies"""
|
"""以dict方式返回cookies"""
|
||||||
return super().cookies
|
return super().cookies
|
||||||
|
|
||||||
|
@property
|
||||||
|
def user_agent(self):
|
||||||
|
"""返回user agent"""
|
||||||
|
if self._mode == 's':
|
||||||
|
return super().user_agent
|
||||||
|
elif self._mode == 'd':
|
||||||
|
return super(SessionPage, self).user_agent
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def session(self):
|
def session(self):
|
||||||
"""返回Session对象,如未初始化则按配置信息创建"""
|
"""返回Session对象,如未初始化则按配置信息创建"""
|
||||||
|
@ -67,6 +67,9 @@ class WebPageTab(SessionPage, ChromiumTab):
|
|||||||
@property
|
@property
|
||||||
def cookies(self) -> dict: ...
|
def cookies(self) -> dict: ...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def user_agent(self) -> str: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def session(self) -> Session: ...
|
def session(self) -> Session: ...
|
||||||
|
|
||||||
|
@ -98,6 +98,11 @@ class SessionPage(BasePage):
|
|||||||
except Exception:
|
except Exception:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def user_agent(self):
|
||||||
|
"""返回user agent"""
|
||||||
|
return self.session.headers.get('user-agent', '')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def download_path(self):
|
def download_path(self):
|
||||||
"""返回下载路径"""
|
"""返回下载路径"""
|
||||||
|
@ -60,6 +60,9 @@ class SessionPage(BasePage):
|
|||||||
@property
|
@property
|
||||||
def json(self) -> Union[dict, None]: ...
|
def json(self) -> Union[dict, None]: ...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def user_agent(self) -> str: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def download_path(self) -> str: ...
|
def download_path(self) -> str: ...
|
||||||
|
|
||||||
|
@ -182,6 +182,14 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
|
|||||||
"""以dict方式返回cookies"""
|
"""以dict方式返回cookies"""
|
||||||
return super().cookies
|
return super().cookies
|
||||||
|
|
||||||
|
@property
|
||||||
|
def user_agent(self):
|
||||||
|
"""返回user agent"""
|
||||||
|
if self._mode == 's':
|
||||||
|
return super().user_agent
|
||||||
|
elif self._mode == 'd':
|
||||||
|
return super(SessionPage, self).user_agent
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def session(self):
|
def session(self):
|
||||||
"""返回Session对象,如未初始化则按配置信息创建"""
|
"""返回Session对象,如未初始化则按配置信息创建"""
|
||||||
@ -339,8 +347,8 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if copy_user_agent:
|
if copy_user_agent:
|
||||||
selenium_user_agent = self.run_cdp('Runtime.evaluate', expression='navigator.userAgent;')['result']['value']
|
user_agent = self.run_cdp('Runtime.evaluate', expression='navigator.userAgent;')['result']['value']
|
||||||
self.session.headers.update({"User-Agent": selenium_user_agent})
|
self.session.headers.update({"User-Agent": user_agent})
|
||||||
|
|
||||||
set_session_cookies(self.session, self._get_driver_cookies())
|
set_session_cookies(self.session, self._get_driver_cookies())
|
||||||
|
|
||||||
|
@ -66,6 +66,9 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
|
|||||||
@property
|
@property
|
||||||
def cookies(self) -> dict: ...
|
def cookies(self) -> dict: ...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def user_agent(self) -> str: ...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def session(self) -> Session: ...
|
def session(self) -> Session: ...
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user