PythonChallenge Level 5:
http://www.pythonchallenge.com/pc/def/peak.html
图片下方给出了文字提示“Pronounce it”,根据PythonChallenge的尿性,右键查看网页源代码
联系前面提示知 peak hell 发音类似 python中的pickle模块,又分析源代码打开12行中的链接src,得到一串乱码字符,很想pickle模块中序列化了数据后的样式,故将其pickle.load()进内存,打印出来继续查看
拿到这一串乱码之后,想了很久,没摸到风,故Google之:其意是按照给出了的数据打印图形,空格符‘ ’打印95次,跟着‘ ’打印14次、‘#’打印5次类推。加一句代码即可按其意打印
代码如下(中间很多注释掉的是自己边做边测试内容,最后优化代码如下):
import pickle
import urllib2
#import string
#import json
response = urllib2.urlopen('http://www.pythonchallenge.com/pc/def/banner.p')
# html = response.read()
# print html
# f = open('pc5.txt', 'wb')
# f.write(html)
# f.close()
# f = open('pc5.txt', 'rb')
file_pic = pickle.load(response)
#save the list(file_pic) to 'unserPc5.txt'
# f = open('unserPc5.txt', 'wb')
# s = str(file_pic)
# print s
# f.write(s)
#demoDictList is the value we want format to output
# jsonDumpsIndentStr = json.dumps(file_pic, indent=1);
# print "jsonDumpsIndentStr=",jsonDumpsIndentStr;
for line in file_pic:
print ''.join(map(lambda pair:pair[0] * pair[1], line))
# print file_pic
# f.close()
最后得到结果为channel,按惯例替换URL即可至 Level 6
PythonChallenge Level 6:
http://www.pythonchallenge.com/pc/def/channel.html
点击图片下方等PayPal 捐赠按钮,果真是出来捐赠页面,没什么提示,按照pythonchallenge的尿性,检查网页源代码,分析下来顶部html标签有方的zip有些古怪,尝试将channel换成zip,出来提示“ yes, find the zip “, 退回并将“ .html ” 后缀换成 .zip , Download下来文件“ channel.zip ” ,其中有将近上千个数字命名的文本文件,open the readme.txt file which says ” begin with 90052″
coding:
import re
import os
def get_Nothing(nothing, count = 1):
f_name = nothing + '.txt'
print 'Opening the file ', f_name
os.chdir('/Python/channel')
f = open(f_name, 'r')
count += 1
text = f.read()
print text, '\n'
next_nothing = re.findall(r'\d+', text)
f.close()
os.remove(f_name)
try:
return get_Nothing(next_nothing[0], count)
except IndexError:
print 'Opend %s files total'%count
print 'Cannot find the Nothing and all we have is this sentence:\n', text
get_Nothing('90052')
solve it and get this:
collect the comments
So , what the hell are the comments ? –> search in google .
And then try use ZiPFIle module , here cames the code:
filename = './channel.zip'
def download_zipfile():
import urllib2
zf = urllib2.urlopen('http://www.pythonchallenge.com/pc/def/channel.zip')
output = open(filename,'wb')
output.write(zf.read())
output.close()
def process():
from zipfile import ZipFile
file_list = ZipFile(filename)
import re
regex = re.compile(r'(\d+)$')
comments = []
nothing = '90052'
try:
for info in file_list.infolist():
fn = '%s.txt' % nothing
comments.append(file_list.getinfo(fn).comment)
nothing = regex.search(file_list.read(fn,'r')).group()
except:
print ''.join(comments)
if __name__ == '__main__':
process()
ZipFile.
infolist
(
)
Return a list containing a
ZipInfo
object for each member of the archive. The objects are in the same order as their entries in the actual ZIP file on disk if an existing archive was opened
runing the code and you will get this :
then tey hockery.html and get this:
“It’s in the air, look at the letters”
So is oxygen!
PythonChallenge Level 7:
http://www.pythonchallenge.com/pc/def/oxygen.html