推荐学习书目
› 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
sadan9
V2EX  ›  Python

求教: urlparse.parse_qs 遇到中文怎么办……

  •  
  •   sadan9 · Jun 7, 2016 · 4715 views
    This topic created in 3765 days ago, the information mentioned may be changed or developed.
    解析类似 xxx?text=测试 用 urlparse.parse_qs('text', []) 解出来的结果类似['\xb2\xe2\xca\xd4']

    而且 chrome 和 ie 还不一样……

    怎么统一转成 UTF-8

    求解……
    2 replies  •  2016-06-07 18:48:56 +08:00
    3dwelcome
        1
    3dwelcome  
       Jun 7, 2016
    可以用一个 is_utf8 函数,自动判断一下是 GBK 还是 UTF8.

    貌似和页面的 charset 有关系,统一弄成 utf8 ,方便很多。
    Slienc7
        2
    Slienc7  
       Jun 7, 2016
    根据来源判断编码类型;
    IE 默认也是 UTF-8 编码吧,你的 IE 可能太旧。
    b'\xb2\xe2\xca\xd4'.decode("gbk")
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   3003 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 13:06 · PVG 21:06 · LAX 06:06 · JFK 09:06
    ♥ Do have faith in what you're doing.