推荐学习书目
› 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 · Oct 13, 2016 · 2799 views
    This topic created in 3645 days ago, the information mentioned may be changed or developed.
    我想将中文转化为 utf-8 格式传递给 url ,请问怎么转换,,搜了好几遍也没搜到,,
    下面这样并不能访问,,

    para = '你的名字'

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

    requests.get("https://movie.douban.com/subject_search",params={"cat":1002,"search_text":"你的名字"})
    sudoz
        7
    sudoz  
       Oct 13, 2016
    requests —— HTTP for HUMAN
    harryw
        8
    harryw  
    OP
       Oct 13, 2016
    @aploium 也好,谢谢了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   885 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 23:16 · PVG 07:16 · LAX 16:16 · JFK 19:16
    ♥ Do have faith in what you're doing.