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
harryw
V2EX  ›  Python

Python3.x 的编码问题,求教

  •  
  •   harryw · 2016-10-13 18:41:02 +08:00 · 1801 次点击
    这是一个创建于 2760 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我想将中文转化为 utf-8 格式传递给 url ,请问怎么转换,,搜了好几遍也没搜到,,
    下面这样并不能访问,,

    para = '你的名字'

    url = 'https://movie.douban.com/subject_search?search_text='+para+'&cat=1002'
    8 条回复    2016-10-13 20:02:16 +08:00
    XiaoxiaoPu
        1
    XiaoxiaoPu  
       2016-10-13 18:43:54 +08:00
    7sDream
        2
    7sDream  
       2016-10-13 18:46:43 +08:00
    这是 urlencode ,你去搜搜吧……好像在 urllib.parser 包里。
    finalspeed
        3
    finalspeed  
       2016-10-13 19:07:12 +08:00 via Android
    urllib.parse.quote(para)
    harryw
        4
    harryw  
    OP
       2016-10-13 19:18:11 +08:00
    @7sDream 谢谢,解决了,是 urllib.parse 里的 quote 方法,
    harryw
        5
    harryw  
    OP
       2016-10-13 19:18:30 +08:00
    @finalspeed 对的
    aploium
        6
    aploium  
       2016-10-13 19:53:37 +08:00   ❤️ 1
    把它交给 requests 处理吧..

    requests.get("https://movie.douban.com/subject_search",params={"cat":1002,"search_text":"你的名字"})
    sudoz
        7
    sudoz  
       2016-10-13 19:58:50 +08:00
    requests —— HTTP for HUMAN
    harryw
        8
    harryw  
    OP
       2016-10-13 20:02:16 +08:00
    @aploium 也好,谢谢了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1010 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 23:54 · PVG 07:54 · LAX 16:54 · JFK 19:54
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.