pythonchallenge--4

来源:互联网 发布:js 初始化二维array 编辑:程序博客网 时间:2024/05/16 06:51

先贴代码吧。

from urllib import *import reimport ossrc = urlopen(r'http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345')nexturl = Noneurl = r'http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing='lasturl = r'http://www.pythonchallenge.com/pc/def/'log = open(r'E:\log.log','a')while True:    nexturl = src.readline()    nextid = nexturl[-5:]    try:        nextid = int(nextid)    except:        print('exit#:'+nexturl)        os.startfile(lasturl+nexturl)        break    nexturl = url+str(nextid)    log.write('next url-->'+nexturl)    print('next url-->'+nexturl)    src.close()    src = urlopen(nexturl)

题目要求不断地用新网页中的数字替换url中的数字所以..

运行的很慢,最后是这个结果:http://www.pythonchallenge.com/pc/def/peak.html