推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
INT21H
V2EX  ›  Python

html 文件以 utf-8 编码储存了 \u6211\u5728\u5317\u4eac 这样字符,现在需要在 Python 中将这些解码为 utf-8 ,应该怎么做?

  •  
  •   INT21H · Jun 13, 2012 · 6379 views
    This topic created in 5227 days ago, the information mentioned may be changed or developed.
    4 replies  •  1970-01-01 08:00:00 +08:00
    fengluo
        1
    fengluo  
       Jun 13, 2012
    print u'\u6211\u5728\u5317\u4eac'.encode('utf-8')
    INT21H
        2
    INT21H  
    OP
       Jun 13, 2012
    @fengluo 问题是是个 html 文件,基本上都是这种 href=\"javascript:void(0);\">\u8f6c\u53d1<\/a> ,所以需要先 re 匹配到 \uXXXX 然后才能 encode ,该怎么做呢。。
    cute
        3
    cute  
       Jun 13, 2012   ❤️ 3
    '\u6211\u5728\u5317\u4eac'.decode('raw_unicode_escape')
    INT21H
        4
    INT21H  
    OP
       Jun 13, 2012
    @cute 十分感谢!
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2678 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 03:17 · PVG 11:17 · LAX 20:17 · JFK 23:17
    ♥ Do have faith in what you're doing.