urlparse (scheme、netloc、path等)


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:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM