Chinaunix首页 | 论坛 | 博客
  • 博客访问: 108889
  • 博文数量: 49
  • 博客积分: 2612
  • 博客等级: 少校
  • 技术积分: 431
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-01 14:31
个人简介

来来去去

文章分类

全部博文(49)

文章存档

2015年(1)

2012年(4)

2011年(1)

2010年(42)

2009年(1)

我的朋友

分类: Python/Ruby

2010-02-02 18:22:03

Level 6

ZIP document:

图片中有一条牛仔裤(拉链的英文名为:zipper)。
Title提示为pair.
源码中有〈!-- 〈-- zip --〉字样。

从 下载zip文件
解压这个ZIP文件,里面有一个readme文件提示:
welcome to my zipped list.
hint1: start from 90052
hint2: answer is inside the zip
从这里可以看出跟Level 4差不多,就是反复从文件中提取下一文件的文件名。


import os
import sys
import re

def get_nextfile(fPath):
    src=open(fPath).read()
    num=re.search('\d+',src)
    if not num:
        print src
        return num.group(1)
    else:
        return num.group(0)

if __name__=='__main__':
    pDir='E:\python challenge\channel'+'\\'
    fileName='
90052.txt'
    fPath=pDir+fileName
    for n in range(1000):
        print n
        num=get_nextfile(fPath)
        fPath=pDir+num+'.txt'
        print fPath
    


执行后显示:
collect the comments

这个comments 就在ZIP文件里面,ZIP有一个对像叫ZipFile.comment。
ZipFile.comment
The comment text associated with the ZIP file. If assigning a comment to a ZipFile instance created with mode ‘a’ or ‘w’, this should be a string no longer than 65535 bytes. Comments longer than this will be truncated in the written archive when ZipFile.close() is called.


import sys
import os
import re
import zipfile

if __name__=='__main__':
    comment=[]
    f=zipfile.ZipFile('E:\python challenge\channel.zip','r')
    nothing='90052'
    nextFile=nothing+'.txt'
    #print zipfile.is_zipfile('E:\python challenge\channel.zip')
    while(1):
        try:
            comment.append(f.getinfo(nextFile).comment)
            nothing=re.search('\d+',f.open(nextFile).read()).group()
            nextFile=nothing+'.txt'
        except:
            break
    f.close()  #close zip file
    print ''.join(comment)


也可以利用代码从网站上下载ZIP文件:

from StringIO import StringIO

zobj = StringIO()
zobj.write(urllib.urlopen("").read())
z = zipfile.ZipFile(zobj)


阅读(542) | 评论(0) | 转发(0) |
0

上一篇:Pickle 序列化

下一篇:7 Image

给主人留下些什么吧!~~