- 论坛徽章:
- 0
|
Level 6ZIP document: http://docs.python.org/library/zipfile.html
图片中有一条牛仔裤(拉链的英文名为:zipper)。
Title提示为pair.
源码中有〈!-- 〈-- zip --〉字样。
从http://www.pythonchallenge.com/pc/def/channel.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.commentThe 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("http://pythonchallenge.com/pc/def/channel.zip").read())
z = zipfile.ZipFile(zobj)
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/107101/showart_2167782.html |
|