MCPcopy Create free account
hub / github.com/seleniumbase/SeleniumBase / load

Method load

seleniumbase/undetected/cdp_driver/browser.py:1206–1241  ·  view source on GitHub ↗

Load all cookies (or a subset, controlled by `pattern`) from a file created by :py:meth:`~save_cookies`. :param file: :param pattern: Regex style pattern string. Any cookie that has a domain, key, or value field which matches the

(self, file: PathLike = ".session.dat", pattern: str = ".*")

Source from the content-addressed store, hash-verified

1204 pickle.dump(cookies, save_path.open("w+b"))
1205
1206 async def load(self, file: PathLike = ".session.dat", pattern: str = ".*"):
1207 """
1208 Load all cookies (or a subset, controlled by `pattern`)
1209 from a file created by :py:meth:`~save_cookies`.
1210 :param file:
1211 :param pattern: Regex style pattern string.
1212 Any cookie that has a domain, key,
1213 or value field which matches the pattern will be included.
1214 Default = ".*" (all)
1215 Eg: the pattern "(cf|.com|nowsecure)" will include cookies which:
1216 - Have a string "cf" (cloudflare)
1217 - Have ".com" in them, in either domain, key or value field.
1218 - Contain "nowsecure"
1219 :type pattern: str
1220 """
1221 pattern = re.compile(pattern)
1222 save_path = pathlib.Path(file).resolve()
1223 cookies = pickle.load(save_path.open("r+b"))
1224 included_cookies = []
1225 connection = None
1226 for _tab in self._browser.tabs:
1227 if getattr(_tab, "closed", None):
1228 continue
1229 connection = _tab
1230 break
1231 else:
1232 connection = self._browser.connection
1233 for cookie in cookies:
1234 for match in pattern.finditer(str(cookie.__dict__)):
1235 included_cookies.append(cookie)
1236 logger.debug(
1237 "Loaded cookie for matching pattern '%s' => (%s: %s)"
1238 % (pattern.pattern, cookie.name, cookie.value)
1239 )
1240 break
1241 await connection.send(cdp.network.set_cookies(included_cookies))
1242
1243 async def clear(self):
1244 """

Callers 3

load_cookiesMethod · 0.80
handle_prefsMethod · 0.80
__init__Method · 0.80

Calls 2

openMethod · 0.45
sendMethod · 0.45

Tested by

no test coverage detected