-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathl17.py
51 lines (37 loc) · 1.22 KB
/
l17.py
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
50
51
'''
Created on 2013-4-8
@author: GunBar
'''
import re, urllib, urllib2, bz2, xmlrpclib
# First of all, get the data that is hidden within the "Set-Cookie" headers:
uri = "http://www.pythonchallenge.com/pc/def/linkedlist.php?busynothing=%s"
nn_rep = re.compile("the next busynothing is (\d+)")
cookie_val = re.compile("info=([^;]+);")
result = []
n = "12345"
while True:
h = urllib.urlopen(uri % n)
next = h.read()
cookie = h.info().getheader("Set-Cookie")
h.close()
cval = cookie_val.search(cookie)
print(cookie,result)
if cookie and cval:
result.append(urllib.unquote_plus(cval.group(1)))
try:
n = nn_rep.search(next).group(1)
except:
break
print bz2.decompress("".join(result))
# Get Leopold's phone numer using the code for level 13:
conn = xmlrpclib.ServerProxy("http://www.pythonchallenge.com/pc/phonebook.php")
print conn.phone("Leopold")
# Now phone Mozart's father and tell him that "the flowers are on their way":
uri = "http://www.pythonchallenge.com/pc/stuff/violin.php"
msg = "the flowers are on their way"
req = urllib2.Request(
uri, headers = { "Cookie": "info=" + urllib.quote_plus(msg)}
)
print urllib2.urlopen(req).read()
if __name__ == '__main__':
pass