Python Web Scraping Cookbook
上QQ阅读APP看书,第一时间看更新

How it works

The .contentype property is implemented as follows:

@property
def contenttype(self):
self.ensure_response()
return self._response.headers['content-type']

The .headers property of the _response object is a dictionary-like class of headers.  The content-type key will retrieve the content-type specified by the server.  This call to the ensure_response() method simply ensures that the .read() function has been executed.