import urllib, re

url = "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=%"
ptrn = "and the next nothing is (\d+)"
num = "12345" 

while True:
    try:
        source = urllib.urlopen(url + num).read()
        num = re.search(nothing_rep, source).group(1)
    except:
        break

