Home
Sign Up
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
V2EX
›
Python
怎样将 url 中非 ASCII 字符的部分 urlencode, UTF-8 环境
laoyuan
·
laoyuan
·
Jul 19, 2015
· 3111 views
This topic created in 4017 days ago, the information mentioned may be changed or developed.
url = '
http://doman.com/中文
' #有些不太正规的网站url 就是这样任性的
得到
http://doman.com/%E4%B8%AD%E6%96%87
urllib.quote( )不行,误伤冒号了
Supplement 1 ·
Jul 19, 2015
误伤url 中所有需要转义的非字母ASCII字符
中非
冒号
utf
5 replies
•
2015-07-23 14:22:40 +08:00
1
lixia625
Jul 19, 2015
先把 http:// 拿走
2
laoyuan
OP
Jul 19, 2015
@
lixia625
误伤太多,比如 url = '
http://domain.com/?中文&+,'
见 rfc3986
3
kaneg
Jul 22, 2015
reserved = ';/:@&=+$,'
print urllib.quote(url, reserved)
不过奇怪的是,唯独?不能加入reserved,否则中文都变成?了
4
laoyuan
OP
Jul 22, 2015
1
@
kaneg
不止这些字符,~ 在url 里也很常见。我感觉应该有什么包可以,反正粘到浏览器地址栏里,浏览器可以正确的转义
5
jack139
Jul 23, 2015
好像有个urllib.quote_plus,或是urllib2,记不清了
About
·
Help
·
Advertise
·
Blog
·
API
·
FAQ
·
Solana
·
988 Online
Highest 6679
·
Select Language
创意工作者们的社区
World is powered by solitude
VERSION: ce1cc7fc · 34ms ·
UTC 19:25
·
PVG 03:25
·
LAX 12:25
·
JFK 15:25
♥ Do have faith in what you're doing.
❯