1 import urllib.request
2
3 response = urllib.request.urlopen('placekitten/g/500/600')# 返回文件对象response
4 cat_imag = response.read()
5
6 with open('cat_500_600.jpg','wb') as f:
7 f.write(cat_imag)
1 >>> response.geturl()
2 'placekitten/g/500/600'
3 >>> response.info()
4 <httplient.HTTPMessage object at 0x00000000034EAA20>
5 >>> print(response.info())
6 Date: Sat, 27 Jul 2019 02:44:18 GMT
7 ContentType: image/jpeg
8 TransferEncoding: chunked
9 Connection: close
10 SetCookie: __cfduid=d3cd08233581619b9ef8464ae93f7d5ff1564195458; expires=Sun, 26Jul20 02:44:18 GMT; path=/; dain=.placekitten; HttpOnly
11 AccessControlAllowOrigin: *
12 CacheControl: public, maxage=86
13 Expires: Sun, 28 Jul 2019 02:44:18 GMT
14 CFCacheStatus: HIT
15 Age: 66459
16 Vary: AcceptEncoding
17 Server: cloudflare
18 CFRAY: 4fcb454ecc35ce6bLHR
19
20
21 >>> response.getcode()
22 200
上一篇:Python基础入门学习笔记 037 类和对象:面向对象编程
下一篇:Python基础入门学习笔记 046 魔法方法:描述符(Property的原理)
python









