I know that I can iterate through the cookies in a cookiejar, and this would allow me to find a cookie with a particular name - but does the CookieJar object itself have any methods I can call to get a certain cookie by name?
It just saves me having to write a helper method that already exists.
Yes, the
__iter__method will go through each cookie inCookieJar.A cookie is not just a name and value pair. In its long list (17) of properties, there is
domainandpath. A domain value of.ibm.comwould be applicable to the websitemail.ibm.comfor example. A domain value ofibm.comand path value of/abcwould not apply to the web pageibm.com/index.htm. So by supplying the name alone is insufficient to find the value of an applicable cookie inCookieJar.Though the
__iter__method will return a list ofcookieobjects easily, examplelist(cj), the internal structure ofCookieJaris not a simple list. Internals about theCookieJarclass is here.