From 29de18c023c07f2e85d229e9ceca5eaba8d657ef Mon Sep 17 00:00:00 2001 From: g1879 Date: Mon, 8 Jan 2024 18:58:56 +0800 Subject: [PATCH] 4.0.1 --- DrissionPage/__init__.py | 2 +- DrissionPage/_pages/chromium_tab.py | 12 +++++++----- DrissionPage/_pages/chromium_tab.pyi | 21 ++++++++++++++++++++- setup.py | 2 +- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/DrissionPage/__init__.py b/DrissionPage/__init__.py index 5eb95ff..0f1467c 100644 --- a/DrissionPage/__init__.py +++ b/DrissionPage/__init__.py @@ -14,4 +14,4 @@ from ._configs.chromium_options import ChromiumOptions from ._configs.session_options import SessionOptions __all__ = ['ChromiumPage', 'ChromiumOptions', 'SessionOptions', 'SessionPage', 'WebPage', '__version__'] -__version__ = '4.0.0' +__version__ = '4.0.1' diff --git a/DrissionPage/_pages/chromium_tab.py b/DrissionPage/_pages/chromium_tab.py index 9eaf97e..cbab53e 100644 --- a/DrissionPage/_pages/chromium_tab.py +++ b/DrissionPage/_pages/chromium_tab.py @@ -10,7 +10,7 @@ from copy import copy from .._base.base import BasePage from .._configs.session_options import SessionOptions from .._functions.web import set_session_cookies, set_browser_cookies -from .._pages.chromium_base import ChromiumBase, get_mhtml +from .._pages.chromium_base import ChromiumBase, get_mhtml, get_pdf from .._pages.session_page import SessionPage from .._units.setter import TabSetter, WebPageTabSetter from .._units.waiter import TabWaiter @@ -60,13 +60,15 @@ class ChromiumTab(ChromiumBase): self._wait = TabWaiter(self) return self._wait - def save(self, path=None, name=None): - """把当前页面保存为mhtml文件,如果path和name参数都为None,只返回mhtml文本 + def save(self, path=None, name=None, as_pdf=False, **kwargs): + """把当前页面保存为文件,如果path和name参数都为None,只返回文本 :param path: 保存路径,为None且name不为None时保存在当前路径 :param name: 文件名,为None且path不为None时用title属性值 - :return: mhtml文本 + :param as_pdf: 为Ture保存为pdf,否则为mhtml且忽略kwargs参数 + :param kwargs: pdf生成参数 + :return: as_pdf为True时返回bytes,否则返回文件文本 """ - return get_mhtml(self, path, name) + return get_pdf(self, path, name, kwargs) if as_pdf else get_mhtml(self, path, name) def __repr__(self): return f'' diff --git a/DrissionPage/_pages/chromium_tab.pyi b/DrissionPage/_pages/chromium_tab.pyi index 7735312..de61132 100644 --- a/DrissionPage/_pages/chromium_tab.pyi +++ b/DrissionPage/_pages/chromium_tab.pyi @@ -44,7 +44,26 @@ class ChromiumTab(ChromiumBase): @property def wait(self) -> TabWaiter: ... - def save(self, path: Union[str, Path] = None, name: str = None) -> str: ... + def save(self, + path: Union[str, Path] = None, + name: str = None, + as_pdf: bool = False, + landscape: bool = ..., + displayHeaderFooter: bool = ..., + printBackground: bool = ..., + scale: float = ..., + paperWidth: float = ..., + paperHeight: float = ..., + marginTop: float = ..., + marginBottom: float = ..., + marginLeft: float = ..., + marginRight: float = ..., + pageRanges: str = ..., + headerTemplate: str = ..., + footerTemplate: str = ..., + preferCSSPageSize: bool = ..., + generateTaggedPDF: bool = ..., + generateDocumentOutline: bool = ...) -> Union[bytes, str]: ... class WebPageTab(SessionPage, ChromiumTab): diff --git a/setup.py b/setup.py index 4cfbfa7..4e39d05 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ with open("README.md", "r", encoding='utf-8') as fh: setup( name="DrissionPage", - version="4.0.0", + version="4.0.1", author="g1879", author_email="g1879@qq.com", description="Python based web automation tool. It can control the browser and send and receive data packets.",