-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathPyCookie.py
More file actions
28 lines (23 loc) · 1001 Bytes
/
Copy pathPyCookie.py
File metadata and controls
28 lines (23 loc) · 1001 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import http.cookiejar
import urllib.request, urllib.parse
ID_USERNAME = 'id_username'
ID_PASSWORD = 'id_password'
USERNAME = 'you@email.com'
PASSWORD = 'mypassword'
LOGIN_URL = 'https://bitbucket.org/account/signin/?next=/'
NORMAL_URL = 'https://bitbucket.org/'
def extract_cookie_info():
cj = http.cookiejar.CookieJar()
login_data = urllib.parse.urlencode({ID_USERNAME: USERNAME,
ID_PASSWORD: PASSWORD}).encode("utf-8")
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
resp = opener.open(LOGIN_URL, login_data)
for cookie in cj:
print("----First time cookie: %s --> %s" % (cookie.name, cookie.value))
print("Headers: %s" % resp.headers)
resp = opener.open(NORMAL_URL)
for cookie in cj:
print("++++Second time cookie: %s --> %s" % (cookie.name, cookie.value))
print("Headers: %s" % resp.headers)
if __name__ == '__main__':
extract_cookie_info()