Question

Hello all… I am using Python to try to simulate login my work email, web base.

Now a problem lies on the first page of login. I observe the login process through IE9’s F12 (Developer tool) and found there are in total 3 cookies generated.

However when I use below scripts to visit the first page of login, there are only 2 cookies found. How could this be? How can I have all the cookies retrieved?

(I’ve cleared all the cache, cookie history, and empty the fold of Temporary Internet Files before catching)

loginUrl = "http://www.company.com/"

cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
urllib2.install_opener(opener)
resp = urllib2.urlopen(loginUrl)

for index, cookie in enumerate(cj):
    print '[',index, ']',cookie

Thanks.

Was it helpful?

Solution

This is because the first two cokies was returned from server read about this:

HTTP/1.1 200 OK
Content-type: text/html
Set-Cookie: foo=10
Set-Cookie: bar=20; Expires=Fri, 30 Sep 2011 11:48:00 GMT

the third one was generated by javascript:

$( document ).ready(function() {

});     
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top