37,736
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title id="pageTitle">有色金属:一周市场概况 行业的估值水平-[中财网]</title>
<meta content="False" name="vs_showGrid"/>
<meta content="JavaScript" name="vs_defaultClientScript"/>
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema"/>
<base target="_blank"/>
</head
Connection: close
Date: Thu, 17 Jul 2008 08:19:00 GMT
Server: Microsoft-IIS/6.0
MicrosoftOfficeWebServer: 5.0_Pub
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Cache-Control: private
Content-Type: text/html; charset=utf-8
Content-Length: 15045
>>> s = urllib.urlopen('http://www.cfi.net.cn/p20080716001458.html ').read()
>>> class MyCode:
... def __init__(self, s):
... self.__codetype = ''
... self.__s = s
... def Decode(self):
... CODES = ['utf-8', 'gbk', ] ##可以在此增加字符编码方式
... for code in CODES:
... try:
... self.__s = self.__s.decode(code)
... self.__codetype = code
... break
... except:
... continue
... def Encode(self, codetype):
... self.__s = self.__s.encode(codetype)
... self.__codetype = codetype
... def GetStr(self):
... return self.__s
...
>>> m = MyCode(s)
>>> m.Decode()
>>> m.Encode('utf-8')
>>> m.Decode()
>>> m.Encode('gbk')
>>> print m.GetStr()
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title id="pageTitle">有色金属:一周市场概况