python urllib2模拟浏览器请求 爬虫

来源:互联网 发布:手机电视直播回放软件 编辑:程序博客网 时间:2024/05/15 07:36
#coding:utf-8import urllib2ua_headers={    "User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0"}request=urllib2.Request("http://baidu.com/",headers=ua_headers)response=urllib2.urlopen(request)html=response.read()print htmlprint response.getcode() #返回响应码print response.geturl() #返回实际urlprint response.info() #返回服务器响应的报头

原创粉丝点击