Python基础入门学习笔记 054 论一只爬虫的自我修养2:实战

发布时间 2023-08-23 11:13:33作者: 一杯清酒邀明月
1 import urllib.request
2 
3 response = urllib.request.urlopen('http://placekitten.com/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 'http://placekitten.com/g/500/600'
 3 >>> response.info()
 4 <http.client.HTTPMessage object at 0x00000000034EAA20>
 5 >>> print(response.info())
 6 Date: Sat, 27 Jul 2019 02:44:18 GMT
 7 Content-Type: image/jpeg
 8 Transfer-Encoding: chunked
 9 Connection: close
10 Set-Cookie: __cfduid=d3cd08233581619b9ef8464ae93f7d5ff1564195458; expires=Sun, 26-Jul-20 02:44:18 GMT; path=/; domain=.placekitten.com; HttpOnly
11 Access-Control-Allow-Origin: *
12 Cache-Control: public, max-age=86400
13 Expires: Sun, 28 Jul 2019 02:44:18 GMT
14 CF-Cache-Status: HIT
15 Age: 66459
16 Vary: Accept-Encoding
17 Server: cloudflare
18 CF-RAY: 4fcb454ecc35ce6b-LHR
19 
20 
21 >>> response.getcode()
22 200