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:

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-24
  • 2022-12-23
  • 2021-12-18
  • 2021-05-28
  • 2022-01-31
猜你喜欢
  • 2021-12-02
  • 2022-12-23
  • 2021-06-04
  • 2021-11-21
  • 2021-10-22
  • 2021-12-11
  • 2021-12-04
相关资源
相似解决方案