This commit is contained in:
g1879 2024-01-08 18:58:56 +08:00
parent c3b58bc90d
commit 29de18c023
4 changed files with 29 additions and 8 deletions

View File

@ -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'

View File

@ -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'<ChromiumTab browser_id={self.browser.id} tab_id={self.tab_id}>'

View File

@ -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):

View File

@ -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.",