January 2019
Beginner
318 pages
8h 23m
English
We can get response headers by calling the info() function on the response object. This returns a dictionary, so we can also extract specific header data from the response. Create a url_response_header.py script and write the following content in it:
import urllib.requestx = urllib.request.urlopen('https://www.imdb.com/')print(x.info())
Run the script as follows:
student@ubuntu:~/work$ python3 url_response_header.py
Here is the output:
Server: ServerDate: Fri, 23 Nov 2018 11:22:48 GMTContent-Type: text/html;charset=UTF-8Transfer-Encoding: chunkedConnection: closeX-Frame-Options: SAMEORIGINContent-Security-Policy: frame-ancestors 'self' imdb.com *.imdb.com *.media-imdb.com withoutabox.com *.withoutabox.com amazon.com ...
Read now
Unlock full access