MCPcopy Create free account
hub / github.com/apify/crawlee-python / set

Method set

src/crawlee/sessions/_cookies.py:88–136  ·  view source on GitHub ↗

Create and store a cookie with modern browser attributes. Args: name: Cookie name. value: Cookie value. domain: Cookie domain. path: Cookie path. expires: Cookie expiration timestamp. http_only: Whether cookie is HTTP-o

(
        self,
        name: str,
        value: str,
        *,
        domain: str = '',
        path: str = '/',
        expires: int | None = None,
        http_only: bool = False,
        secure: bool = False,
        same_site: Literal['Lax', 'None', 'Strict'] | None = None,
        **_kwargs: Any,  # Unknown parameters will be ignored.
    )

Source from the content-addressed store, hash-verified

86 return self._jar
87
88 def set(
89 self,
90 name: str,
91 value: str,
92 *,
93 domain: str = '',
94 path: str = '/',
95 expires: int | None = None,
96 http_only: bool = False,
97 secure: bool = False,
98 same_site: Literal['Lax', 'None', 'Strict'] | None = None,
99 **_kwargs: Any, # Unknown parameters will be ignored.
100 ) -> None:
101 """Create and store a cookie with modern browser attributes.
102
103 Args:
104 name: Cookie name.
105 value: Cookie value.
106 domain: Cookie domain.
107 path: Cookie path.
108 expires: Cookie expiration timestamp.
109 http_only: Whether cookie is HTTP-only.
110 secure: Whether cookie requires secure context.
111 same_site: SameSite cookie attribute value.
112 """
113 cookie = Cookie(
114 version=0,
115 name=name,
116 value=value,
117 port=None,
118 port_specified=False,
119 domain=domain,
120 domain_specified=bool(domain),
121 domain_initial_dot=domain.startswith('.'),
122 path=path,
123 path_specified=bool(path),
124 secure=secure,
125 expires=expires,
126 discard=True,
127 comment=None,
128 comment_url=None,
129 rest={'HttpOnly': ''} if http_only else {},
130 rfc2109=False,
131 )
132
133 if same_site:
134 cookie.set_nonstandard_attr('SameSite', same_site)
135
136 self.jar.set_cookie(cookie)
137
138 def _convert_cookie_to_dict(self, cookie: Cookie) -> CookieParam:
139 """Convert `http.cookiejar.Cookie` to dictionary format.

Callers 15

__init__Method · 0.95
set_cookiesMethod · 0.95
__setitem__Method · 0.95
session_cookiesFunction · 0.95
test_set_basic_cookieFunction · 0.95
_update_metadataMethod · 0.80
_create_storageMethod · 0.80

Calls

no outgoing calls

Tested by 8

session_cookiesFunction · 0.76
test_set_basic_cookieFunction · 0.76
signaling_waitFunction · 0.64
async_listenerFunction · 0.64
launch_crawler_1Function · 0.64
handler_1Function · 0.64