Tuesday, January 23, 2007

Python urllibでcontent-typeをとる

>>> from urllib2 import urlopen
>>> url1 = 'http://www.example.jp'
>>> f = urlopen(url1)
>>> f.info().get('content-type')
'text/html;charset=utf-8'

>>> f.info().get('content-type', 'text/html;charset=utf-8').split(';')[0]
'text/html'

0 Comments:

Post a Comment

<< Home