-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathl17_busynothing.py
More file actions
39 lines (30 loc) · 847 Bytes
/
Copy pathl17_busynothing.py
File metadata and controls
39 lines (30 loc) · 847 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
29
30
31
32
33
34
35
36
37
38
39
import urllib
import re
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)
u = urllib.urlopen(url)
print 'url : %20s' % url.split("/")[-1],
text = u.read()
print 'text : %20s' % text,
sHeaders = str(u.headers)
cook = sHeaders.index("info=")
endcook = sHeaders.index(";", cook)
u.close()
ckie = sHeaders[cook+5:endcook]
ckiechars.append(ckie)
matches = re.findall(regex, text)
if not matches:
break
else:
m = matches[0]
currval = m
print 'new val = %s' % currval
print ckiechars