[Level 6]
Title: now there are pairs
圖片下方是一個PayPal捐贈的圖片鏈接,無其他信息,查看源碼,有兩處注釋:
- <-- zip
- The following has nothing to do with the riddle itself. I just
thought it would be the right point to offer you to donate to the
Python Challenge project. Any amount will be greatly appreciated.
-thesamet
圖片上是拉鏈,英文為zip,源碼注釋有zip锻拘,挺考驗腦洞的,修改url中的html為zip后綴击蹲,下載到channel.zip文件署拟。打開文件,有readme.txt歌豺,打開顯示:
welcome to my zipped list.
hint1: start from 90052
hint2: answer is inside the zip
和Level 4類似推穷,不斷讀取文件直至找到答案。
num = '90052'
suffix = '.txt'
while True:
try:
with open('channel/'+num+suffix,encoding='utf-8') as f:
data = f.read()
print(data)#Next nothing is 83831
num = data.split(' ')[-1]
except:
break
最后的提示是Collect the comments.类咧。不懂馒铃,查看官方文檔,搜索comment無果痕惋,搜索zip区宇,有zipfile模塊,在該頁中搜索comment值戳,出現(xiàn)兩處:ZipFile.comment
和ZipInfo.comment
议谷。使用第一個無果,使用第二個述寡。
import zipfile
comments = []
with zipfile.ZipFile('channel.zip') as zf:
while True:
try:
zi = zf.getinfo(num+suffix)
comments.append(zi.comment.decode('utf-8'))
data = zf.read(num+suffix).decode('utf-8')
num = data.split(' ')[-1]
except:
break
print(''.join(comments))
得到
result
大大的hockey柿隙,修改url叶洞,hockey.html顯示it's in the air. look at the letters.鲫凶,每個大的字母都是由相同的字母組合成,即oxygen衩辟,正好對應提示螟炫,[Level 7]
小結
-
zipfile.ZipFile(file, mode='r', compression=ZIP_STORED, allowZip64=True)
返回ZipFile對象,可用于讀取壓縮的文件艺晴。 -
ZipFile.getinfo(name)
返回ZipInfo對象昼钻。 -
ZipInfo.comment
返回成員的注釋。 -
ZipFile.read(name, pwd=None)
讀取其中的壓縮文件封寞。
Python Challenge Wiki
一種不下載channel.zip文件的方法:
import io,zipfile,urllib.request
zf = zipfile.ZipFile(io.BytesIO(urllib.request.urlopen('http://pythonchallenge.com/pc/def/channel.zip').read()))
1. [`class io.BytesIO([initial_bytes])`](https://docs.python.org/3/library/io.html?highlight=bytesio#io.BytesIO)可以像在二進制模式下打開的文件一樣使用然评。
####[More](http://wiki.pythonchallenge.com/index.php?title=Level6:Main_Page)