首先根据提示从 linkedlist.html 转到 linkedlist.php,进入 level4
点击图片得到链接:http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345
网页内容为:and the next nothing is 44827
将 44827 替换 12345
得到网页链接:http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=44827
得到网页内容:and the next nothing is 45439
由此得知本关目的就在于利用程序循环重复以上过程直至得到结果。
中间可能会中断,可以根据提示修正。
#!/usr/bin/env/python #coding:utf8 ''' Created on May 2, 2013 @author: killua @url: http://www.pythonchallenge.com/pc/def/equality.html @target: http://www.pythonchallenge.com/pc/def/linkedlist.html '''
import urllib import re
defnext_page(nothing_no): try: text = urllib.urlopen('http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=%s' % nothing_no).read() print text m = re.match(r'[^\d]*(\d+)$', text) return m.groups()[0] except: return'END'