python challenge 第六关解法 http://www.pythonchallenge.com
来源:互联网 发布:剑网3小和尚捏脸数据 编辑:程序博客网 时间:2024/05/07 06:51
第六关地址:http://www.pythonchallenge.com/pc/def/channel.html
进到页面后,除了两张图片,别无他物,果断查看网页源代码。
源代码中有这么一句:
<!-- <-- zip -->
好吧,用zip来替换channel试试看先,http://www.pythonchallenge.com/pc/def/zip.html
果然,这张页面虽然存在,不过是一个提示性的作用,页面上只有一句话:
yes. find the zip.
好吧,那么我们回到第六关的源代码,继续查看,源码中的这句话向我们讲明白了,哪些代码是与解题无关的:
<!-- The following has nothing to do with the riddle itself. I justthought it would be the right point to offer you to donate to thePython Challenge project. Any amount will be greatly appreciated. -thesamet-->
意思是,这句注释语句之后的语句只是为了让人来捐款之类的,与解题无关,忽略之,那么现在有用的代码有哪些呢,看看下面:
<html> <!-- <-- zip --> <head> <title>now there are pairs</title> <link rel="stylesheet" type="text/css" href="../style.css"> </head> <body> <center> <img src="channel.jpg">
源码中基本没有任何的可推敲的地方(刚开始我还对“now there are pairs”这个标题推敲了下,把页面图片<imgalt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif"width="1" height="1"> 中得两段文字用内建zip方法试过,当然,结果可想而知)
那么,我们现在换个思维,zip是什么,英文不好的同学查查 google 翻译,zip有拉链之类的意思,好吧,我们看到,第六关页面中的大图片是条牛仔裤,咦,还有拉链,推敲推敲再说。
盯着这条恶心的牛仔裤一会后,我淫荡的笑了,这拉链不就像个字母 y 么?好吧,试试看再说 -_-
事实是,我又一次失败了,这也是一张存在的页面,但是,它的提示会让你吐血的:
It really looks like a Y, isn't it? now, go back.
果断吐血中……………………………………
好吧,再来,zip还能是什么,当然是 zip 包咯,看看页面上好像就是那张大图片是个链接,把后缀改了试试看先,上只有一句话:
http://www.pythonchallenge.com/pc/def/channel.zip
我勒个去,还真有个压缩包!!!
拿着压缩包,我们最想干嘛呢,当然是解压缩咯,解压看看再说,我察,咋这么多文件呢,打开几个看看,吐……,全是如下类型字符串:
Next nothing is XXX # 注释:XXX代表数字类型的字符串记得第六关前面几关中有个也和这种类似,直接考虑用 正则 呗。
对了,解压后,用os.listdir 大体看了下文件,发现文件夹里面有个 readme.txt文件,里面写着:
welcome to my zipped list.hint1: start from 90052hint2: answer is inside the zip
好的,果断写个小脚本运行起来再说:
import re, osre_match = re.compile(r'Next nothing is (\d+)').matchfname = '90052'values = []while 1: if 'readme' == fname:print 'Find nothing.'break try: f = open('channel/%s.txt' %fname) s = f.read() f.close() fname = re_match(s).groups()[0] values.append(v) except: print s break
当然,其实上面那段脚本写的确实不咋地,不过用来取个答案是够了,我们可以看到,最后会输出文本如下:Collect the comments.
字面意思是把 comments 集中起来,可是comments我还就只能想到评论之类的意思了。
我解决问题到了这个位置后就没辙了,为啥呢,因为它用到了一个我没用过的模块 zipfile,接下来就需要这个模块的帮助了(真失败,看到zip只能想到内建函数zip,却不知道还有zipfile,功力不够呀),之后如何做,我是Google滴哦,代码如下:
print ''.join(map(lambda i: zipfile.ZipFile('channel.zip').getinfo(i).comment, [i for i in values]))
其中的values是上面的脚本中保存下来查找Collect the comments.所经过的文件名集合。
那么,结果出来咯:
果断打下链接 http://www.pythonchallenge.com/pc/def/hockey.html,可是链接的页面却提示的这么一句话:
it's in the air. look at the letters.
汗,仔细看图片中的 HOCKEY, H 由 O 组成,O 由 X 组成…………
那么,第七关地址是:
http://www.pythonchallenge.com/pc/def/oxygen.html
太耗神了。-_-,我这不就是在做脑筋急转弯么……
上只有一句话:try
- python challenge 第六关解法 http://www.pythonchallenge.com
- python challenge 第三关解法 http://www.pythonchallenge.com
- python challenge 第四关解法 http://www.pythonchallenge.com
- python challenge 第五关解法 http://www.pythonchallenge.com
- python challenge 第二关最简解法 http://www.pythonchallenge.com
- python challenge 第零关解法 http://www.pythonchallenge.com
- pythonchallenge第六关
- python挑战题 http://www.pythonchallenge.com/pc/def/map.html
- python challenge 第三关
- python challenge 第四关
- python challenge 第三关
- python challenge 第四关
- python challenge 第五关
- Python Challenge第二关
- Python Challenge:第八关
- Python Challenge 第九关
- 学习python pythonchallenge第一关
- 关于www.pythonchallenge.com的记录
- 创建单例winform应用程序
- VIE模式的实例
- 还是c链表
- 16个经典面试问题回答思路
- Byte of Python学习笔记二
- python challenge 第六关解法 http://www.pythonchallenge.com
- 谷歌中国已由搜索转为展示广告提供商,转身意味着什么
- VC++ ----> 多线程AfxBeginThread
- jquery+笔记
- Centos6.0 64位版本上安装oracle11g
- 查询修改表
- 面向ICPC的书籍简介
- jQuery 1.6版发布,区分DOM的attributes和properties
- Byte of Python学习笔记三