閱讀816 返回首頁    go 阿裏雲 go 技術社區[雲棲]


pythonchallenge_level9

level9

地址:https://www.pythonchallenge.com/pc/return/good.html
源碼:git@code.aliyun.com:qianlizhixing12/PythonChallenge.git。
問題:使用PIL.Image對象show連接源碼中first,second點。

#!/usr/bin/env python3
# -*- coding:UTF-8 -*-

# Level 9

import os
import urllib.request

url = "https://www.pythonchallenge.com/pc/return/good.html"
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)
'''
方式一
# use the opener to fetch a URL
x = opener.open(url)
print(x.read())
'''
# 方式二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().decode("utf8")
response.close

import re

stmp = re.findall("first:\n((?:.|\n)*)\n\nsecond:((?:.|\n)*)\n\n-->", body)
first, second = stmp[0][0].replace("\n", "").split(","), stmp[0][1].replace("\n", "").split(",")
first, second = list(map(int, first)), list(map(int, second))

import PIL.Image
import PIL.ImageDraw

img = PIL.Image.new("RGB", (640, 480))
draw = PIL.ImageDraw.Draw(img)
draw.line(first)
draw.line(second)
img.show()

最後更新:2017-10-01 09:33:01

  上一篇:go  免費好用的阿裏雲雲盾證書服務(https證書)申請步驟
  下一篇:go  pythonchallenge_level8