urlparse (scheme、netloc、path等)

时间:2017-09-04 18:40:11   收藏:0   阅读:2350

python2

from urllib2 import urlparse

python3

from urlib.parse import urlparse

 

>>> url = "http://localhost/test.py?a=hello&b=world "
>>> from urlib2 import urlparse
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named urlib2
>>> from urllib2 import urlparse
>>> result = urlparse.urlparse(url)
>>> result
ParseResult(scheme=‘http‘, netloc=‘localhost‘, path=‘/test.py‘, params=‘‘, query=‘a=hello&b=world ‘, fragment=‘‘)

result.scheme : 网络协议

result.netloc: 服务器位置(也有可能是用户信息)

result.path: 网页文件在服务器中的位置

result.params: 可选参数

result.query: &连接键值对

result.fragment:

 

原文:http://www.cnblogs.com/AbsolutelyPerfect/p/7474961.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!