import urllib.request
url="http://blog.csdn.net"
header=("User-Agent",'User-Agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36')
opn=urllib.request.build_opener()
opn.addheaders=[header]
data=opn.open(url).read()
print(data.decode())
转载于:https://www.cnblogs.com/xiesongyou/p/7868414.html