mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
微调
This commit is contained in:
parent
15a1a7e73b
commit
abd6d4fb24
@ -27,8 +27,8 @@ class Drission(object):
|
|||||||
ini_path: str = None,
|
ini_path: str = None,
|
||||||
proxy: dict = None):
|
proxy: dict = None):
|
||||||
"""初始化,可接收现成的WebDriver和Session对象,或接收它们的配置信息生成对象 \n
|
"""初始化,可接收现成的WebDriver和Session对象,或接收它们的配置信息生成对象 \n
|
||||||
:param driver_or_options: driver对象或chrome设置,Options类或设置字典
|
:param driver_or_options: driver对象或DriverOptions、Options类,传入False则创建空配置对象
|
||||||
:param session_or_options: Session对象或设置
|
:param session_or_options: Session对象或设置字典,传入False则创建空配置对象
|
||||||
:param ini_path: ini文件路径
|
:param ini_path: ini文件路径
|
||||||
:param proxy: 代理设置
|
:param proxy: 代理设置
|
||||||
"""
|
"""
|
||||||
@ -331,7 +331,7 @@ class Drission(object):
|
|||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
if copy_user_agent:
|
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)
|
self.set_cookies(self.driver.get_cookies(), set_session=True)
|
||||||
|
|
||||||
@ -358,17 +358,6 @@ class Drission(object):
|
|||||||
|
|
||||||
self.set_cookies(cookies, set_driver=True)
|
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:
|
def close_driver(self, kill: bool = False) -> None:
|
||||||
"""关闭driver和浏览器"""
|
"""关闭driver和浏览器"""
|
||||||
if self._driver:
|
if self._driver:
|
||||||
@ -394,6 +383,18 @@ class Drission(object):
|
|||||||
self.close_session()
|
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]:
|
def _check_port(debugger_address: str) -> Union[bool, None]:
|
||||||
"""检查端口是否被占用 \n
|
"""检查端口是否被占用 \n
|
||||||
:param debugger_address: 浏览器地址及端口
|
:param debugger_address: 浏览器地址及端口
|
||||||
|
2
setup.py
2
setup.py
@ -6,7 +6,7 @@ with open("README.md", "r", encoding='utf-8') as fh:
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="DrissionPage",
|
name="DrissionPage",
|
||||||
version="2.3.0",
|
version="2.3.1",
|
||||||
author="g1879",
|
author="g1879",
|
||||||
author_email="g1879@qq.com",
|
author_email="g1879@qq.com",
|
||||||
description="A module that integrates selenium and requests session, encapsulates common page operations.",
|
description="A module that integrates selenium and requests session, encapsulates common page operations.",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user