python urllib2 请求包含cookie信息

cookie_file = “/tmp/netcraft_cookie.txt”
global_cookie = cookielib.MozillaCookieJar(cookie_file)
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(global_cookie))

pq = PyQuery(opener.open(sso_url).read())

csrf_token = pq(“input[name=’csrf_token’]”).attr(“value”)
destination = pq(“input[name=’destination’]”).attr(“value”)
print “get page \n csrf_token : %s \n destination: %s ” % (csrf_token,destination)
global_cookie.save(ignore_discard=True, ignore_expires=True)



注:转载请注明文章来源:流影部落阁

发表评论

电子邮件地址不会被公开。 必填项已用*标注