python访问的时候,将debug信息打印出来

来源:互联网 发布:纵横概预算软件 编辑:程序博客网 时间:2024/05/17 06:42
import urllib2httpHandler = urllib2.HTTPHandler(debuglevel=1)httpsHandler = urllib2.HTTPSHandler(debuglevel=1)opener = urllib2.build_opener(httpHandler, httpsHandler)urllib2.install_opener(opener)response = urllib2.urlopen('http://www.baidu.com')print 'a'print response.read()



免得抓包  在打印台都打印出来    请求,相应信息打印出来


send: 'GET / HTTP/1.1\r\nAccept-Encoding: identity\r\nHost: www.baidu.com\r\nConnection: close\r\nUser-Agent: Python-urllib/2.7\r\n\r\n'
reply: 'HTTP/1.1 200 OK\r\n'
header: Date: Wed, 30 Jul 2014 15:06:10 GMT
header: Content-Type: text/html; charset=utf-8
header: Transfer-Encoding: chunked
header: Connection: Close
header: Vary: Accept-Encoding
header: Set-Cookie: BAIDUID=6C110EA08744D95D4FFDAA6EAB5B87C8:FG=1; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
header: Set-Cookie: BDSVRTM=0; path=/
header: P3P: CP=" OTI DSP COR IVA OUR IND COM "
header: Cache-Control: private
header: Cxy_all: baidu+38e329b0efa4e62de8845f9602ba55f8
header: Expires: Wed, 30 Jul 2014 15:05:22 GMT
header: X-Powered-By: HPHP
header: Server: BWS/1.1
header: BDPAGETYPE: 1
header: BDQID: 0xe3822dd3000081dc
header: BDUSERID: 0


0 0