import urllib.request, urllib.error, urllib.parse
opener = urllib.request.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
opener.open('http://www.example.com/')
How do I add a header to urllib2 opener?