mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
增加set.cookie()
This commit is contained in:
parent
41a8c550bb
commit
b47a903ae1
@ -972,8 +972,18 @@ class ChromiumBaseSetter(object):
|
|||||||
js = f'localStorage.removeItem("{item}");' if item is False else f'localStorage.setItem("{item}","{value}");'
|
js = f'localStorage.removeItem("{item}");' if item is False else f'localStorage.setItem("{item}","{value}");'
|
||||||
return self._page.run_js_loaded(js, as_expr=True)
|
return self._page.run_js_loaded(js, as_expr=True)
|
||||||
|
|
||||||
|
def cookie(self, cookie):
|
||||||
|
"""设置单个cookie
|
||||||
|
:param cookie: cookie信息
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
if isinstance(cookie, str):
|
||||||
|
self.cookies(cookie)
|
||||||
|
else:
|
||||||
|
self.cookies([cookie])
|
||||||
|
|
||||||
def cookies(self, cookies):
|
def cookies(self, cookies):
|
||||||
"""设置cookies值
|
"""设置多个cookie,注意不要传入单个
|
||||||
:param cookies: cookies信息
|
:param cookies: cookies信息
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
|
@ -274,6 +274,8 @@ class ChromiumBaseSetter(object):
|
|||||||
|
|
||||||
def local_storage(self, item: str, value: Union[str, bool]) -> None: ...
|
def local_storage(self, item: str, value: Union[str, bool]) -> None: ...
|
||||||
|
|
||||||
|
def cookie(self, cookies: Union[RequestsCookieJar, str, dict]) -> None: ...
|
||||||
|
|
||||||
def cookies(self, cookies: Union[RequestsCookieJar, list, tuple, str, dict]) -> None: ...
|
def cookies(self, cookies: Union[RequestsCookieJar, list, tuple, str, dict]) -> None: ...
|
||||||
|
|
||||||
def headers(self, headers: dict) -> None: ...
|
def headers(self, headers: dict) -> None: ...
|
||||||
|
@ -360,7 +360,7 @@ class WebPageTabSetter(ChromiumBaseSetter):
|
|||||||
self._chromium_setter = ChromiumBaseSetter(self._page)
|
self._chromium_setter = ChromiumBaseSetter(self._page)
|
||||||
|
|
||||||
def cookies(self, cookies):
|
def cookies(self, cookies):
|
||||||
"""添加cookies信息到浏览器或session对象
|
"""添加多个cookies信息到浏览器或session对象,注意不要传入单个
|
||||||
:param cookies: 可以接收`CookieJar`、`list`、`tuple`、`str`、`dict`格式的`cookies`
|
:param cookies: 可以接收`CookieJar`、`list`、`tuple`、`str`、`dict`格式的`cookies`
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
|
@ -337,8 +337,18 @@ class SessionPageSetter(object):
|
|||||||
"""
|
"""
|
||||||
self._page.timeout = second
|
self._page.timeout = second
|
||||||
|
|
||||||
|
def cookie(self, cookie):
|
||||||
|
"""为Session对象设置单个cookie
|
||||||
|
:param cookie: cookie信息
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
if isinstance(cookie, str):
|
||||||
|
self.cookies(cookie)
|
||||||
|
else:
|
||||||
|
self.cookies([cookie])
|
||||||
|
|
||||||
def cookies(self, cookies):
|
def cookies(self, cookies):
|
||||||
"""为Session对象设置cookies
|
"""为Session对象设置多个cookie,注意不要传入单个
|
||||||
:param cookies: cookies信息
|
:param cookies: cookies信息
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
@Author : g1879
|
@Author : g1879
|
||||||
@Contact : g1879@qq.com
|
@Contact : g1879@qq.com
|
||||||
"""
|
"""
|
||||||
|
from http.cookiejar import Cookie
|
||||||
from typing import Any, Union, Tuple, List
|
from typing import Any, Union, Tuple, List
|
||||||
|
|
||||||
from DownloadKit import DownloadKit
|
from DownloadKit import DownloadKit
|
||||||
@ -169,6 +170,8 @@ class SessionPageSetter(object):
|
|||||||
|
|
||||||
def timeout(self, second: float) -> None: ...
|
def timeout(self, second: float) -> None: ...
|
||||||
|
|
||||||
|
def cookie(self, cookie: Union[Cookie, str, dict]) -> None: ...
|
||||||
|
|
||||||
def cookies(self, cookies: Union[RequestsCookieJar, list, tuple, str, dict]) -> None: ...
|
def cookies(self, cookies: Union[RequestsCookieJar, list, tuple, str, dict]) -> None: ...
|
||||||
|
|
||||||
def headers(self, headers: dict) -> None: ...
|
def headers(self, headers: dict) -> None: ...
|
||||||
|
Loading…
x
Reference in New Issue
Block a user