试图让登录脚本工作,我不断返回相同的登录页面,所以我打开了http流的调试(由于https,不能使用wireshark等).
我什么都没有,所以我复制了这个例子,它有效.对google.com的任何查询都有效,但是我的目标页面没有显示调试,有什么区别?如果是重定向,我希望看到第一个获取/重定向标头,http:// google重定向也是如此.
import urllib
import urllib2
import pdb
h=urllib2.HTTPHandler(debuglevel=1)
opener = urllib2.build_opener(h)
urllib2.install_opener(opener)
print '================================'
data = urllib2.urlopen('http://google.com').read()
print '================================'
data = urllib2.urlopen('https://google.com').read()
print '================================'
data = urllib2.urlopen('https://members.poolplayers.com/default.aspx').read()
print '================================'
data = urllib2.urlopen('https://google.com').read()
Run Code Online (Sandbox Code Playgroud)
当我跑步时,我得到了这个.
$ python ex.py
================================
send: 'GET / HTTP/1.1\r\nAccept-Encoding: identity\r\nHost: google.com\r\nConnection: close\r\nUser-Agent: Python-urllib/2.7\r\n\r\n'
reply: 'HTTP/1.1 301 Moved Permanently\r\n'
header: Location: http://www.google.com/
header: Content-Type: text/html; charset=UTF-8
header: Date: Sat, 02 Jul 2011 16:20:11 GMT
header: Expires: Mon, 01 Aug 2011 16:20:11 GMT
header: Cache-Control: public, …Run Code Online (Sandbox Code Playgroud)