This commit is contained in:
g1879 2022-01-13 17:23:14 +08:00
parent 15a1a7e73b
commit abd6d4fb24
2 changed files with 17 additions and 16 deletions

View File

@ -27,8 +27,8 @@ class Drission(object):
ini_path: str = None,
proxy: dict = None):
"""初始化可接收现成的WebDriver和Session对象或接收它们的配置信息生成对象 \n
:param driver_or_options: driver对象或chrome设置Options类或设置字典
:param session_or_options: Session对象或设置
:param driver_or_options: driver对象或DriverOptionsOptions类传入False则创建空配置对象
:param session_or_options: Session对象或设置字典传入False则创建空配置对象
:param ini_path: ini文件路径
:param proxy: 代理设置
"""
@ -331,7 +331,7 @@ class Drission(object):
:return: None
"""
if copy_user_agent:
self.user_agent_to_session(self.driver, self.session)
user_agent_to_session(self.driver, self.session)
self.set_cookies(self.driver.get_cookies(), set_session=True)
@ -358,17 +358,6 @@ class Drission(object):
self.set_cookies(cookies, set_driver=True)
def user_agent_to_session(self, driver: WebDriver = None, session: Session = None) -> None:
"""把driver的user-agent复制到session \n
:param driver: 来源driver对象
:param session: 目标session对象
:return: None
"""
driver = driver or self.driver
session = session or self.session
selenium_user_agent = driver.execute_script("return navigator.userAgent;")
session.headers.update({"User-Agent": selenium_user_agent})
def close_driver(self, kill: bool = False) -> None:
"""关闭driver和浏览器"""
if self._driver:
@ -394,6 +383,18 @@ class Drission(object):
self.close_session()
def user_agent_to_session(driver: WebDriver, session: Session) -> None:
"""把driver的user-agent复制到session \n
:param driver: 来源driver对象
:param session: 目标session对象
:return: None
"""
driver = driver
session = session
selenium_user_agent = driver.execute_script("return navigator.userAgent;")
session.headers.update({"User-Agent": selenium_user_agent})
def _check_port(debugger_address: str) -> Union[bool, None]:
"""检查端口是否被占用 \n
:param debugger_address: 浏览器地址及端口

View File

@ -6,7 +6,7 @@ with open("README.md", "r", encoding='utf-8') as fh:
setup(
name="DrissionPage",
version="2.3.0",
version="2.3.1",
author="g1879",
author_email="g1879@qq.com",
description="A module that integrates selenium and requests session, encapsulates common page operations.",