Get all cookies. :param requests_cookie_format: when True, returns python http.cookiejar.Cookie objects, compatible with requests library and many others. :type requests_cookie_format: bool
(
self, requests_cookie_format: bool = False
)
| 1110 | self._browser = browser |
| 1111 | |
| 1112 | async def get_all( |
| 1113 | self, requests_cookie_format: bool = False |
| 1114 | ) -> List[Union[cdp.network.Cookie, "http.cookiejar.Cookie"]]: |
| 1115 | """ |
| 1116 | Get all cookies. |
| 1117 | :param requests_cookie_format: when True, |
| 1118 | returns python http.cookiejar.Cookie objects, |
| 1119 | compatible with requests library and many others. |
| 1120 | :type requests_cookie_format: bool |
| 1121 | """ |
| 1122 | connection = None |
| 1123 | for _tab in self._browser.tabs: |
| 1124 | if getattr(_tab, "closed", None): |
| 1125 | continue |
| 1126 | connection = _tab |
| 1127 | break |
| 1128 | else: |
| 1129 | connection = self._browser.connection |
| 1130 | cookies = await connection.send(cdp.network.get_cookies()) |
| 1131 | if requests_cookie_format: |
| 1132 | import requests.cookies |
| 1133 | |
| 1134 | return [ |
| 1135 | requests.cookies.create_cookie( |
| 1136 | name=c.name, |
| 1137 | value=c.value, |
| 1138 | domain=c.domain, |
| 1139 | path=c.path, |
| 1140 | expires=c.expires, |
| 1141 | secure=c.secure, |
| 1142 | ) |
| 1143 | for c in cookies |
| 1144 | ] |
| 1145 | return cookies |
| 1146 | |
| 1147 | async def set_all(self, cookies: List[cdp.network.CookieParam]): |
| 1148 | """ |
no test coverage detected