V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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 · 4414 views
    This topic created in 3623 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   ·   Solana   ·   2814 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 01:45 · PVG 09:45 · LAX 18:45 · JFK 21:45
    ♥ Do have faith in what you're doing.