HTTPヘッダー取得
#! /usr/bin/python
# coding: UTF-8
import urllib2
url = "http://webings.net/sample/"
r = urllib2.Request(url)
r.add_header("User-Agent", "Python")
print "Content-type: text/html"
print """
<html>
<head>
<title>HTTPヘッダー取得</title>
</head>
<body>
<table align="center" border="1" bordercolor="#9999ff">
<caption>ヘッダー</caption>
"""
for k, v in urllib2.urlopen(r).headers.items():
print """
<tr><td>%s</td><td>%s</td></tr>
""" % (k, v)
print """
</table>
</body>
</html>
"""
〔 実行する 〕