源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

python用于url解码和中文解析的小脚本(python url decoder)

  • 时间:2020-10-24 19:05 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:python用于url解码和中文解析的小脚本(python url decoder)
[url=http://yac163.svn.sourceforge.net/viewvc/yac163/trunk/yac163-nox/Pic.py?revision=198&view=markup]http://yac163.svn.sourceforge.net/viewvc/yac163/trunk/yac163-nox/Pic.py?revision=198&view=markup[/url] 參考我這個很古老code裡面的#102-147行 給每個decode和encode調用加上(…,”ignore”)。
[u]复制代码[/u] 代码如下:
def strdecode( string,charset=None ):      if isinstance(string,unicode):          return string      if charset:          try:              return string.decode(charset)          except UnicodeDecodeError:              return _strdecode(string)      else:          return _strdecode(string)  def _strdecode(string):      try:          return string.decode('utf8')      except UnicodeDecodeError:          try:              return string.decode('gb2312')          except UnicodeDecodeError:              try:                  return string.decode('gbk')              except UnicodeDecodeError:                  return string.decode('gb18030')  def strencode( string,charset=None ):      if isinstance(string,str):          return string      if charset:          try:              return string.encode(charset)          except UnicodeEncodeError:              return _strencode(string)      else:          return _strencode(string)  def _strencode(string):      try:          return string.encode('utf8')      except UnicodeEncodeError:          try:              return string.encode('gb2312')          except UnicodeEncodeError:              try:                  return string.encode('gbk')              except UnicodeEncodeError:                  return string.encode('gb18030')
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部