理解urllib.parse in Python||URL结构

本文介绍了URL(统一资源定位符)的基本概念及其组成部分,包括如何指定互联网上的资源位置及检索方式。文中还详细解释了URL的语法结构,并通过Python的urllib库演示了URL解析的方法。
  • URL

    A URL (Uniform Resource Locator), more commonly known as a “web address”, specifies the location of a resource (such as a web page) on the internet.

    The URL also specifies how to retrieve that resource, also known as the “Protocol”, such as HTTP, HTTPS, FTP, etc.

    A URL is a specific type of Uniform Resource Identifier (URI).

    The URI generic syntax consists of a hierarchical sequnce of five components:

    URI = scheme:[//authority]path[?query][#fragment]
    

    where the authority component divides into three subcomponents:

    authority=[useinfo@]host[:port]
    
  • urllib

  • urllib.parse.rulparse(urlstring, scheme='', allow_fragments=True)

    Parse a URL into six components, returing a 6-item names tuple. This correspons to the general structure of a URL : scheme://netloc/path;parameters?query#fragment

  • urllib.parse.parse_qs(qs, keep_blank_values=False, strict_parsing=False, encoding='utf-8', errors='replace', max_num_fields=None)

    Parse a query string given as a string argument. Data are returned as a dictionary.

  • References

  1. Moz : URLs
  2. wikipedia
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值