4.python爬虫浏览器伪装技术
#python爬虫的浏览器伪装技术 #爬取csdn博客,会返回403错误,因为对方服务器会对爬虫进行屏蔽,此时需要伪装成浏览器才能爬取 #浏览器伪装,一般通过报头进行。 import urllib.request url="http://blog.csdn.net/bingoxubin/article/details/78503370" headers=("User-Agent","浏览器中User-Agent的值") opener=urllib.request.build_opener() opener.add_handlers=[headers] data=opener.open(url).read() print(len(data))