V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2016-06-07 17:23:09 +08:00 · 3736 次点击
    这是一个创建于 2873 天前的主题,其中的信息可能已经有所发展或是发生改变。
    解析类似 xxx?text=测试 用 urlparse.parse_qs('text', []) 解出来的结果类似['\xb2\xe2\xca\xd4']

    而且 chrome 和 ie 还不一样……

    怎么统一转成 UTF-8

    求解……
    2 条回复    2016-06-07 18:48:56 +08:00
    3dwelcome
        1
    3dwelcome  
       2016-06-07 17:34:54 +08:00
    可以用一个 is_utf8 函数,自动判断一下是 GBK 还是 UTF8.

    貌似和页面的 charset 有关系,统一弄成 utf8 ,方便很多。
    Slienc7
        2
    Slienc7  
       2016-06-07 18:48:56 +08:00
    根据来源判断编码类型;
    IE 默认也是 UTF-8 编码吧,你的 IE 可能太旧。
    b'\xb2\xe2\xca\xd4'.decode("gbk")
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3827 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 10:17 · PVG 18:17 · LAX 03:17 · JFK 06:17
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.