level12
地址:http://www.pythonchallenge.com/pc/return/evil.html。
源码:git@code.aliyun.com:qianlizhixing12/PythonChallenge.git。
问题:按提示处理图片。
#!/usr/bin/env python3
# -*- coding:UTF-8 -*-
# Level 12
import os
import urllib.request
filename = "evil2.gfx"
url = "http://www.pythonchallenge.com/pc/return/" + filename
userinfo = {"realm":"inflate", "uri":url, "user":"huge", "passwd":"file"}
# create a password manager
password_mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
# Add the username and password
password_mgr.add_password(**userinfo)
# create "opener" (OpenerDirector instance)
handler = urllib.request.HTTPBasicAuthHandler(password_mgr)
# create "opener" (OpenerDirector instance)
opener = urllib.request.build_opener(handler)
# Install the opener.all calls to urllib.request.urlopen use our opener.
urllib.request.install_opener(opener)
response = urllib.request.urlopen(url)
body = response.read()
response.close
import PIL.Image
for i in range(5):
tmpfname = str(i)
tmpfile = open(tmpfname, "wb")
tmpfile.write(body[i::5])
tmpfile.close()