2012-03-19 55 views
1

我正在嘗試使用Python獲取頁面,並使用cookie jar。使用url2lib檢查請求標題

jar = cookielib.CookieJar() 
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) 
opener.addheaders = [('User-agent', 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)')] 
response = opener.open('http://www.example.com/') 
print response.info() 

使用上面,我能得到響應頭,但比其他Wireshark的,我可以看到請求頭? urllib2發送了什麼?

回答

0

不,雖然the docs表示沒有太多的添加。你可以設置一個http server in python,首先發送請求到它,拉出標題,然後檢查它們。但是如果你有Wireshark,那麼使用它就不那麼容易了。