PythonChanllenge第四关:Linkedlist

http://www.pythonchallenge.com/pc/def/linkedlist.php

源代码中的提示:

<a href="linkedlist.php?nothing=12345"><img src="chainsaw.jpg" border="0"/></a>
脚本:

import urllib.request
import re

nextno = 12345

for i in range(500):
    page = urllib.request.urlopen("http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=%s" % (nextno))
    text = page.read().decode("utf-8")
    nextno = re.search('and the next nothing is (\d+)', text)
    if nextno:
            nextno = nextno.groups()[0]
            print(nextno+'\n')
    else:
            print(text)
            break

中间提示:“Yes. Divide by two and keep going.”,将nextno修改继续执行即可。

你可能感兴趣的:(PythonChanllenge第四关:Linkedlist)