mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-11-29 18:47:34 +08:00
ChromiumPage的set_user_agent()增加platform参数;SessionPage和WebPage增加set_user_agent()方法
This commit is contained in:
parent
82c4140fff
commit
0268a9d990
@ -567,12 +567,16 @@ class ChromiumBase(BasePage):
|
||||
raise RuntimeError('该元素已不在当前页面中。')
|
||||
raise
|
||||
|
||||
def set_user_agent(self, ua):
|
||||
def set_user_agent(self, ua, platform=None):
|
||||
"""为当前tab设置user agent,只在当前tab有效
|
||||
:param ua: user agent字符串
|
||||
:param platform: platform字符串
|
||||
:return: None
|
||||
"""
|
||||
self._wait_driver.Network.setUserAgentOverride(userAgent=ua)
|
||||
keys = {'userAgent': ua}
|
||||
if platform:
|
||||
keys['platform'] = platform
|
||||
self._wait_driver.Emulation.setUserAgentOverride(**keys)
|
||||
|
||||
def get_session_storage(self, item=None):
|
||||
"""获取sessionStorage信息,不设置item则获取全部
|
||||
|
@ -169,7 +169,7 @@ class ChromiumBase(BasePage):
|
||||
|
||||
def run_cdp(self, cmd: str, **cmd_args) -> dict: ...
|
||||
|
||||
def set_user_agent(self, ua: str) -> None: ...
|
||||
def set_user_agent(self, ua: str, platform:str=None) -> None: ...
|
||||
|
||||
def get_session_storage(self, item: str = None) -> Union[str, dict, None]: ...
|
||||
|
||||
|
@ -90,6 +90,10 @@ class SessionPage(BasePage):
|
||||
for i in headers:
|
||||
self.session.headers[i] = headers[i]
|
||||
|
||||
def set_user_agent(self, ua):
|
||||
"""设置user agent"""
|
||||
self.session.headers['user-agent'] = ua
|
||||
|
||||
def __call__(self, loc_or_str, timeout=None):
|
||||
"""在内部查找元素
|
||||
例:ele2 = ele1('@id=ele_id')
|
||||
|
@ -43,6 +43,8 @@ class SessionPage(BasePage):
|
||||
|
||||
def set_headers(self, headers: dict) -> None: ...
|
||||
|
||||
def set_user_agent(self, ua: str) -> None: ...
|
||||
|
||||
def __call__(self,
|
||||
loc_or_str: Union[Tuple[str, str], str, SessionElement],
|
||||
timeout: float = None) -> Union[SessionElement, str, None]: ...
|
||||
|
@ -389,6 +389,11 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
|
||||
elif self._mode == 'd':
|
||||
return self._get_driver_cookies(as_dict)
|
||||
|
||||
def set_user_agent(self, ua, platform=None):
|
||||
"""设置user agent,d模式下只有当前tab有效"""
|
||||
super().set_user_agent(ua)
|
||||
super(SessionPage, self).set_user_agent(ua, platform)
|
||||
|
||||
def _get_driver_cookies(self, as_dict=False):
|
||||
"""获取浏览器cookies
|
||||
:param as_dict: 以dict形式返回
|
||||
|
@ -130,6 +130,8 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
|
||||
|
||||
def get_cookies(self, as_dict: bool = False, all_domains: bool = False) -> Union[dict, list]: ...
|
||||
|
||||
def set_user_agent(self, ua: str, platform: str = None) -> None: ...
|
||||
|
||||
def _get_driver_cookies(self, as_dict: bool = False) -> dict: ...
|
||||
|
||||
def set_cookies(self, cookies, set_session: bool = False, set_driver: bool = False) -> None: ...
|
||||
|
@ -58,9 +58,9 @@ python 版本:3.6 及以上
|
||||
|
||||
- 运行速度更快
|
||||
|
||||
- 可以跨 iframe 查找元素,无需切入切出
|
||||
- 可以跨`<iframe>`查找元素,无需切入切出
|
||||
|
||||
- 把 iframe 看作普通元素,获取后可直接在其中查找元素,逻辑更清晰
|
||||
- 把`<iframe>`看作普通元素,获取后可直接在其中查找元素,逻辑更清晰
|
||||
|
||||
- 可以同时操作浏览器中的多个标签页,即使标签页为非激活状态,无需切换
|
||||
|
||||
@ -68,6 +68,8 @@ python 版本:3.6 及以上
|
||||
|
||||
- 可以对整个网页截图,包括视口外的部分(90以上版本浏览器支持)
|
||||
|
||||
- 可处理非`open`状态的 shadow-root
|
||||
|
||||
## 🎇 亮点功能
|
||||
|
||||
除了以上优点,本库还内置了无数人性化设计。
|
||||
|
@ -72,6 +72,8 @@ python 版本:3.6 及以上
|
||||
|
||||
- 可以对整个网页截图,包括视口外的部分(90以上版本浏览器支持)
|
||||
|
||||
- 可处理非`open`状态的 shadow-root
|
||||
|
||||
## 🎇 亮点功能
|
||||
|
||||
除了以上优点,本库还内置了无数人性化设计。
|
||||
|
138
docs/_sidebar.md
138
docs/_sidebar.md
@ -1,89 +1,89 @@
|
||||
* [📣 1 概述](README.md)
|
||||
|
||||
* [☀️ 2 特性和亮点](#)
|
||||
|
||||
* [💖 2.1 贴心设计](2_features\1_intimate_design.md)
|
||||
* [🌟 2.2 特性演示](#)
|
||||
* [⭐ 与 requests 对比](2_features\2_features_demos\1_compare_with_requests.md)
|
||||
* [⭐ 与 selenium 对比](2_features\2_features_demos\2_compare_with_selenium.md)
|
||||
* [⭐ 模式切换](2_features\2_features_demos\3_switch_mode.md)
|
||||
* [⭐ 获取元素属性](2_features\2_features_demos\4_get_element_attributes.md)
|
||||
* [⭐ 下载文件](2_features\2_features_demos\5_download_file.md)
|
||||
|
||||
* [💖 2.1 贴心设计](2_features/1_intimate_design.md)
|
||||
* [🌟 2.2 特性演示](#)
|
||||
* [⭐ 与 requests 对比](2_features/2_features_demos/1_compare_with_requests.md)
|
||||
* [⭐ 与 selenium 对比](2_features/2_features_demos/2_compare_with_selenium.md)
|
||||
* [⭐ 模式切换](2_features/2_features_demos/3_switch_mode.md)
|
||||
* [⭐ 获取元素属性](2_features/2_features_demos/4_get_element_attributes.md)
|
||||
* [⭐ 下载文件](2_features/2_features_demos/5_download_file.md)
|
||||
|
||||
* [🧭 3 入门指南](#)
|
||||
|
||||
* [🌏 3.1 安装和导入](3_get_start\1_installation_and_import.md)
|
||||
* [🌏 3.2 准备工作](3_get_start\2_before_start.md)
|
||||
* [🌏 3.3 上手示例](#)
|
||||
* [🗺️ 操控浏览器](3_get_start\3_examples\1_control_browser.md)
|
||||
* [🗺️ 收发数据包](3_get_start\3_examples\2_data_packets.md)
|
||||
* [🗺️ 模式切换](3_get_start\3_examples\3_switch_mode.md)
|
||||
* [🌏 3.4 基本概念](3_get_start\4_basic_concept.md)
|
||||
|
||||
* [🌏 3.1 安装和导入](3_get_start/1_installation_and_import.md)
|
||||
* [🌏 3.2 准备工作](3_get_start/2_before_start.md)
|
||||
* [🌏 3.3 上手示例](#)
|
||||
* [🗺️ 操控浏览器](3_get_start/3_examples/1_control_browser.md)
|
||||
* [🗺️ 收发数据包](3_get_start/3_examples/2_data_packets.md)
|
||||
* [🗺️ 模式切换](3_get_start/3_examples/3_switch_mode.md)
|
||||
* [🌏 3.4 基本概念](3_get_start/4_basic_concept.md)
|
||||
|
||||
* [📫 4 SessionPage](#)
|
||||
|
||||
* [✉️ 4.0 概述](4_SessionPge\0_introduction.md)
|
||||
* [✉️ 4.1 创建页面对象](4_SessionPge\1_create_page_object.md)
|
||||
* [✉️ 4.2 访问网页](4_SessionPge\2_visit_web_page.md)
|
||||
* [✉️ 4.3 获取网页信息](4_SessionPge\3_get_page_info.md)
|
||||
* [✉️ 4.4 查找元素](4_SessionPge\4_find_elements.md)
|
||||
* [✉️ 4.5 获取元素信息](4_SessionPge\5_get_element_info.md)
|
||||
* [✉️ 4.6 启动配置](4_SessionPge\6_session_options.md)
|
||||
|
||||
* [✉️ 4.0 概述](4_SessionPge/0_introduction.md)
|
||||
* [✉️ 4.1 创建页面对象](4_SessionPge/1_create_page_object.md)
|
||||
* [✉️ 4.2 访问网页](4_SessionPge/2_visit_web_page.md)
|
||||
* [✉️ 4.3 获取网页信息](4_SessionPge/3_get_page_info.md)
|
||||
* [✉️ 4.4 查找元素](4_SessionPge/4_find_elements.md)
|
||||
* [✉️ 4.5 获取元素信息](4_SessionPge/5_get_element_info.md)
|
||||
* [✉️ 4.6 启动配置](4_SessionPge/6_session_options.md)
|
||||
|
||||
* [🚀 5 ChromiumPage](#)
|
||||
|
||||
* [🛰️ 5.0 概述](5_ChromiumPage\0_introduction.md)
|
||||
* [🛰️ 5.1 创建页面对象](5_ChromiumPage\1_create_page_object.md)
|
||||
* [🛰️ 5.2 访问网页](5_ChromiumPage\2_visit_web_page.md)
|
||||
* [🛰️ 5.3 获取网页信息](5_ChromiumPage\3_get_page_info.md)
|
||||
* [🛰️ 5.4 页面交互](5_ChromiumPage\4_page_operation.md)
|
||||
* [🛰️ 5.5 查找元素](5_ChromiumPage\5_find_elements.md)
|
||||
* [🛰️ 5.6 获取元素信息](5_ChromiumPage\6_get_element_info.md)
|
||||
* [🛰️ 5.7 元素交互](5_ChromiumPage\7_element_operation.md)
|
||||
* [🛰️ 5.8 标签页操作](5_ChromiumPage\8_tab_operation.md)
|
||||
* [🛰️ 5.9 iframe 操作](5_ChromiumPage\9_frame_operation.md)
|
||||
* [🛰️ 5.10 动作链](5_ChromiumPage\10_action_chains.md)
|
||||
* [🛰️ 5.11 浏览器启动配置](5_ChromiumPage\11_browser_options.md)
|
||||
|
||||
* [🛰️ 5.0 概述](5_ChromiumPage/0_introduction.md)
|
||||
* [🛰️ 5.1 创建页面对象](5_ChromiumPage/1_create_page_object.md)
|
||||
* [🛰️ 5.2 访问网页](5_ChromiumPage/2_visit_web_page.md)
|
||||
* [🛰️ 5.3 获取网页信息](5_ChromiumPage/3_get_page_info.md)
|
||||
* [🛰️ 5.4 页面交互](5_ChromiumPage/4_page_operation.md)
|
||||
* [🛰️ 5.5 查找元素](5_ChromiumPage/5_find_elements.md)
|
||||
* [🛰️ 5.6 获取元素信息](5_ChromiumPage/6_get_element_info.md)
|
||||
* [🛰️ 5.7 元素交互](5_ChromiumPage/7_element_operation.md)
|
||||
* [🛰️ 5.8 标签页操作](5_ChromiumPage/8_tab_operation.md)
|
||||
* [🛰️ 5.9 iframe 操作](5_ChromiumPage/9_frame_operation.md)
|
||||
* [🛰️ 5.10 动作链](5_ChromiumPage/10_action_chains.md)
|
||||
* [🛰️ 5.11 浏览器启动配置](5_ChromiumPage/11_browser_options.md)
|
||||
|
||||
* [🌌 6 WebPage](#)
|
||||
|
||||
* [🪐 6.0 概述](6_WebPage\0_introduction.md)
|
||||
* [🪐 6.1 创建页面对象](6_WebPage\1_create_page_object.md)
|
||||
* [🪐 6.2 模式切换](6_WebPage\2_mode_switch.md)
|
||||
* [🪐 6.3 独有的功能](6_WebPage\3_webpage_function.md)
|
||||
|
||||
* [🪐 6.0 概述](6_WebPage/0_introduction.md)
|
||||
* [🪐 6.1 创建页面对象](6_WebPage/1_create_page_object.md)
|
||||
* [🪐 6.2 模式切换](6_WebPage/2_mode_switch.md)
|
||||
* [🪐 6.3 独有的功能](6_WebPage/3_webpage_function.md)
|
||||
|
||||
* [🧰 7 进阶使用](#)
|
||||
|
||||
* [⚙️ 7.1 配置文件的使用](7_advance\1_ini_file.md)
|
||||
* [⚙️ 7.2 easy_set 方法](7_advance\2_easy_set.md)
|
||||
* [⚙️ 7.3 下载文件](7_advance\3_download.md)
|
||||
* [⚙️ 7.4 加速浏览器数据采集](7_advance\4_accelerate_collecting.md)
|
||||
* [⚙️ 7.5 打包程序](7_advance\5_packaging.md)
|
||||
* [⚙️ 7.6 监听浏览器网络](7_advance\6_monitor_network.md)
|
||||
|
||||
* [⚙️ 7.1 配置文件的使用](7_advance/1_ini_file.md)
|
||||
* [⚙️ 7.2 easy_set 方法](7_advance/2_easy_set.md)
|
||||
* [⚙️ 7.3 下载文件](7_advance/3_download.md)
|
||||
* [⚙️ 7.4 加速浏览器数据采集](7_advance/4_accelerate_collecting.md)
|
||||
* [⚙️ 7.5 打包程序](7_advance/5_packaging.md)
|
||||
* [⚙️ 7.6 监听浏览器网络](7_advance/6_monitor_network.md)
|
||||
|
||||
* [🛠 8 旧版使用方法](#)
|
||||
|
||||
* [🔨 8.0 概述](8_MixPage\0_introduction.md)
|
||||
* [🔨 8.1 创建页面对象](8_MixPage\1_create_page_object.md)
|
||||
* [🔨 8.2 访问网页](8_MixPage\2_visit_web_page.md)
|
||||
* [🔨 8.3 查找页面元素](8_MixPage\3_find_page_element.md)
|
||||
* [🔨 8.4 获取元素信息](8_MixPage\4_get_element_info.md)
|
||||
* [🔨 8.5 元素操作](8_MixPage\5_element_operation.md)
|
||||
* [🔨 8.6 获取网页信息](8_MixPage\6_get_page_info.md)
|
||||
* [🔨 8.7 页面操作](8_MixPage\7_page_operation.md)
|
||||
* [🔨 8.8 cookies 的使用](8_MixPage\8_cookies.md)
|
||||
* [🔨 8.9 Drission 对象](8_MixPage\9_Drission.md)
|
||||
* [🔨 8.10 对接 selenium 及 requests 代码](8_MixPage\10_work_with_selenium_and_requests.md)
|
||||
* [🔨 8.11 使用其它系统或浏览器](8_MixPage\11_use_other_browser.md)
|
||||
* [🔨 8.12 DriverPage 和 SessionPage](8_MixPage\12_DriverPage_and_SessionPage.md)
|
||||
|
||||
* [🔨 8.0 概述](8_MixPage/0_introduction.md)
|
||||
* [🔨 8.1 创建页面对象](8_MixPage/1_create_page_object.md)
|
||||
* [🔨 8.2 访问网页](8_MixPage/2_visit_web_page.md)
|
||||
* [🔨 8.3 查找页面元素](8_MixPage/3_find_page_element.md)
|
||||
* [🔨 8.4 获取元素信息](8_MixPage/4_get_element_info.md)
|
||||
* [🔨 8.5 元素操作](8_MixPage/5_element_operation.md)
|
||||
* [🔨 8.6 获取网页信息](8_MixPage/6_get_page_info.md)
|
||||
* [🔨 8.7 页面操作](8_MixPage/7_page_operation.md)
|
||||
* [🔨 8.8 cookies 的使用](8_MixPage/8_cookies.md)
|
||||
* [🔨 8.9 Drission 对象](8_MixPage/9_Drission.md)
|
||||
* [🔨 8.10 对接 selenium 及 requests 代码](8_MixPage/10_work_with_selenium_and_requests.md)
|
||||
* [🔨 8.11 使用其它系统或浏览器](8_MixPage/11_use_other_browser.md)
|
||||
* [🔨 8.12 DriverPage 和 SessionPage](8_MixPage/12_DriverPage_and_SessionPage.md)
|
||||
|
||||
* [⚡️ 9 示例和技巧](#)
|
||||
|
||||
* [🌠 自动登录码云](9_demos\login_gitee.md)
|
||||
* [🌠 采集猫眼电影 TOP100 榜](9_demos\maoyan_TOP100.md)
|
||||
* [🌠 下载星巴克产品图片](9_demos\starbucks_pics.md)
|
||||
* [🌠 下载豆瓣图书封面图片](9_demos\douban_book_pics.md)
|
||||
* [🌠 多线程操作多标签页](9_demos\multithreading_with_tabs.md)
|
||||
|
||||
* [🌠 自动登录码云](9_demos/login_gitee.md)
|
||||
* [🌠 采集猫眼电影 TOP100 榜](9_demos/maoyan_TOP100.md)
|
||||
* [🌠 下载星巴克产品图片](9_demos/starbucks_pics.md)
|
||||
* [🌠 下载豆瓣图书封面图片](9_demos/douban_book_pics.md)
|
||||
* [🌠 多线程操作多标签页](9_demos/multithreading_with_tabs.md)
|
||||
|
||||
* [🔖 10 版本历史](10_history.md)
|
||||
|
||||
|
@ -18,12 +18,9 @@
|
||||
<link href="//unpkg.com/gitalk/dist/gitalk.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="./ignore/font.css">
|
||||
-->
|
||||
<style>
|
||||
<!-- <style>
|
||||
/* body {font-family: PingFang; } */
|
||||
|
||||
|
||||
|
||||
</style>
|
||||
</style> -->
|
||||
|
||||
</head>
|
||||
|
||||
@ -59,8 +56,8 @@
|
||||
coverpage: false,
|
||||
subMaxLevel: 2,
|
||||
pagination: {
|
||||
previousText: 'PREVIOUS',
|
||||
nextText: 'NEXT',
|
||||
previousText: '上一页',
|
||||
nextText: '下一页',
|
||||
crossChapter: true
|
||||
},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user