November 2017
Intermediate to advanced
226 pages
5h 59m
English
We use custom user agent string in the request as following:
>>> import urllib.request
>>> user_agent = ' Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:47.0) Gecko/20100101 Firefox/47.0'
>>> headers = {'User-Agent': user_agent}
>>> request = urllib.request.Request("https://www.packtpub.com/", headers=headers)
>>> with urllib.request.urlopen(request) as response:
... with open('with_new_user_agent.html', 'wb') as out:
... out.write(response.read())
Read now
Unlock full access