Python Challenge 第六关

第六关只有一张图和一个 PayPal 的链接,右键源代码注释中写着 PayPal 是作者要赞助的,跟题目没关系,其他的提示只有注释中写的个 zip。试过下图片,改图片扩展名等等都失败了,最后乱试改了下 url,先把 channel 改了,没用,然后把 html 改成 zip,下载下来一个压缩包。解压出来一看,一堆 txt,其中有个 readme,里面有两句提示:

welcome to my zipped list.

hint1: start from 90052

hint2: answer is inside the zip

看一下其他的文件,都是一句:Next nothing is XXX

看起来跟第四关挺像。就先写个代码查找这个 answer:

path = 'C://Users//Leo//Desktop//channel//'
nothing = '90052'
fileExt = '.txt'
while True:
    fobj = open(path + nothing + fileExt, 'r')
    text = fobj.readline()
    fobj.close()
    txtList = text.split(' ')
    if txtList[-1].isdigit():
        nothing = txtList[-1]
    else:
        break
print '%s.txt: %s' % (nothing, text)

结果输出:Collect the comments.

这个 comments 是什么东西确实难倒我了。去查了一下 zipfile 模块,发现还真有 comment 这个成员,属于 ZipInfo。这样只要得到每个文件的 ZipInfo,就可以提取出 comments了。修改上面的代码,改为使用 zipfile 模块:

zobj = zipfile.ZipFile('C://Users//Leo//Desktop//channel.zip')
fileName = '90052.txt'
cmtList = []
while True:
    zinfo = zobj.getinfo(fileName)
    cmtList.append(zinfo.comment)
    f = zobj.open(fileName)
    nothing = f.readline().split(' ')[-1]
    f.close()
    if nothing.isdigit():
        fileName = nothing + '.txt'
    else:
        break
print ''.join(cmtList)

得到的结果为:

将 url 中的 channel 改为 hockey,又出来一行提示:it's in the air. look at the letters.

再看上面那张图,每个大写字母是由一些小写字母组成,这东西是空气中的,也就是氧气:oxygen。再将 hockey 改为 oxygen,进入下一关:http://www.pythonchallenge.com/pc/def/oxygen.html

原文地址:https://www.cnblogs.com/dukeleo/p/3460961.html