python 爬虫 浏览器伪装

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())
posted @ 2017-11-20 21:43  沧海一粒水  阅读(145)  评论(0编辑  收藏  举报