第6关线索还是比较难找。感觉这个python challenge难度是逐渐增加的,而且刚刚第6关我找线索就很吃力了。打开链接http://www.pythonchallenge.com/pc/def/channel.html 只有一张图片:
第6关
老规矩,找不到线索就按F12,但是打开以后只发现了一个链接,是个赞助作者的PayPal链接,与解题无关。
终于网页源码中
<html>
标签旁边的注释引起了我的注意:网页源码的注释
看到图片上最醒目的就是拉链(英文zip),于是突发奇想,将本题链接中的html换成zip,于是得到了一个channel.zip文件,解压以后里面有许多个数字命名的txt文件和一个readme.txt文件,打开后里面是“welcome to my zipped list. hint1: start from 90052 hint2: answer is inside the zip”。根据提示打开90052.txt文件,内容是“Next nothing is 94191”,跟第4关差不多,于是先写个程序循环它。跟第四关的区别是,这次要采用读文件的方式,而不是请求http。
程序代码如下:
import re
No = '90052'
recon = re.compile(r'Next nothing is (\d+)')
while True:
fileName = "D:/channel/" + No + '.txt'
text = open(fileName, 'r').read()
print(text)
lists = recon.findall(text)
if lists:
No = lists[0]
print("Next file is %s"%(No))
else:
break
得到的输出最后一句是:“Collect the comments.”
comments是什么东西,想了好久没有思路,结合第二个提示“answer is inside the zip”,还是没有思路,于是请教度娘,原来这个题目是要利用zipfile模块,需要提取出zip中文件的comment信息。因为不熟悉zipfile模块,这完全是我的盲区,肯定想不到呀。于是查zipfile模块的用法,修改程序如下:
import re
No = '90052'
recon = re.compile(r'Next nothing is (\d+)')
comments = []
z = zipfile.ZipFile("D:/channel.zip", "r")
while True:
fileName = "D:/channel/" + No + '.txt'
comments.append(z.getinfo(No + ".txt").comment)
text = open(fileName, 'r').read()
print(text)
lists = recon.findall(text)
if lists:
No = lists[0]
print("Next file is %s"%(No))
else:
break
comments_utf8 = []
for i in comments:
comments_utf8.append(i.decode('utf-8'))
print(''.join(comments_utf8))
得到输出:
输出结果
把链接中的channel替换为得到的hockey,又得到一句提示:it's in the air. look at the letters.
再观察刚刚得到的结果,每个字母都是由一个大写字母组成,分别为OXYGEN,这个词是氧气,符合刚刚得到那句提示,将oxygen替换hockey,得到下一关的地址:http://www.pythonchallenge.com/pc/def/oxygen.html