推荐学习书目
› 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 · 2881 views
    This topic created in 3684 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
    7sDream
    Oct 13, 2016
    2
    这是 urlencode ,你去搜搜吧……好像在 urllib.parser 包里。
    finalspeed
    finalspeed
    Oct 13, 2016 via Android
    3
    urllib.parse.quote(para)
    harryw
    harryw
    OP
    Oct 13, 2016
    4
    @7sDream 谢谢,解决了,是 urllib.parse 里的 quote 方法,
    harryw
    harryw
    OP
    Oct 13, 2016
    5
    @finalspeed 对的
    aploium
    aploium
    Oct 13, 2016❤️1
    6
    把它交给 requests 处理吧..

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