python challenge 4

import re
start = time.time()
pattern = "and the next nothing is (\d+)"
re_url = "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing="
nothing = "6711"
url = urlopen(re_url + nothing)
strs = url.read()
obj = re.search(pattern,strs)
while obj:
nothing = obj.group(1)
url = urlopen(re_url + nothing)
strs = url.read()
obj = re.search(pattern,strs)
print obj.group(1)
#http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=16044
#
Yes. Divide by two and keep going.
#
http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=160
#
and the next nothing is 33774
#
http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=66831
#
peak.html
#
http://www.pythonchallenge.com/pc/def/peak.html
#
....
posted @ 2012-02-10 18:21  lcyang  阅读(387)  评论(0编辑  收藏  举报