2009年10月18日日曜日

【Python】urllib2 - http headersをセットする。

import urllib2

url = 'http://vsbabu.org/'

txdata = None
txheaders = {
'User-Agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)',
'Accept-Language': 'en-us',
'Accept-Encoding': 'gzip, deflate, compress;q=0.9',
'Keep-Alive': '300',
'Connection': 'keep-alive',
'Cache-Control': 'max-age=0',
}
req = urllib2.Request(url, txdata, txheaders)
u = urllib2.urlopen(req)
print u.info()
print u.read()
  

http://vsbabu.org/mt/archives/2003/05/27/urllib2_setting_http_headers.html

urllib2モジュール
http://d.hatena.ne.jp/yumimue/20071231/1199129495

0 件のコメント: