-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathl17_busynothing_different.py
More file actions
49 lines (37 loc) · 1.07 KB
/
l17_busynothing_different.py
File metadata and controls
49 lines (37 loc) · 1.07 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import urllib
import re
import bz2
base = ("http://www.pythonchallenge.com/pc/def/linkedlist.php")
param = "busynothing"
currval = "12345"
def makeUrl(base, param, val):
return base + "?" + param + "=" + str(val)
regex = re.compile("([0-9]+$)")
ckiechars = []
while True:
## find "nothing"'s
url = makeUrl(base, param, currval)
resp = urllib.urlopen(url)
print 'url : %32s' % url.split("/")[-1],
text = resp.read()
print 'text : %35s' % text,
respheaders = resp.info()
cookie = resp.info().getheader('Set-Cookie')
cookB = cookie.index("info=")
cookE = cookie.index(";", cookB)
ckievalue = cookie[cookB+5:cookE]
print 'cookie : %3s' % ckievalue,
ckiechars.append(ckievalue)
resp.close()
matches = re.findall(regex, text)
if not matches:
break
else:
m = matches[0]
currval = m
print 'new val = %s' % currval
print
print ckiechars
print "".join(ckiechars)
print urllib.unquote_plus("".join(ckiechars))
print bz2.decompress(urllib.unquote_plus("".join(ckiechars)))