urllib无法正确处理#字符

2024-09-30 05:19:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我的url如下所示:

http://me:me1234#@localhost:8080/

当我在此url上运行urlparse时,它只返回me:me1234,而不是返回me:me1234.@localhost:8080

from six.moves.urllib import parse
o=parse.urlparse('http://me:me1234#@localhost:8080/')
print o

ParseResult(scheme='http',netloc='me:me1234',path='',params='',query='',fragment='@localhost:8080/'))

知道它为什么无法解析#吗?我认为这是一个相当标准的url


Tags: fromimportlocalhosthttpurlparseurllibme
1条回答
网友
1楼 · 发布于 2024-09-30 05:19:18

这是一个fragment。首先need to对其进行编码:

from six.moves.urllib import parse
o=parse.urlparse('http://me:me1234%23@localhost:8080/')
print o

这应该适合你的需要

相关问题 更多 >

    热门问题