- Python Web Scraping Cookbook
- Michael Heydt
- 135字
- 2021-06-30 18:44:13
There's more...
The headers in a response contain a wealth of information. If we look more closely at the headers property of the response, we can see the following headers are returned:
>>> response = urllib.request.urlopen(const.ApodEclipseImage())
>>> for header in response.headers: print(header)
Date
Server
Last-Modified
ETag
Accept-Ranges
Content-Length
Connection
Content-Type
Strict-Transport-Security
And we can see the values for each of these headers.
>>> for header in response.headers: print(header + " ==> " + response.headers[header])
Date ==> Tue, 26 Sep 2017 19:31:41 GMT
Server ==> WebServer/1.0
Last-Modified ==> Thu, 31 Aug 2017 20:26:32 GMT
ETag ==> "547bb44-29c06-5581275ce2b86"
Accept-Ranges ==> bytes
Content-Length ==> 171014
Connection ==> close
Content-Type ==> image/jpeg
Strict-Transport-Security ==> max-age=31536000; includeSubDomains
Many of these we will not examine in this book, but for the unfamiliar it is good to know that they exist.