⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 module-urlparse.html

📁 一本很好的python的说明书,适合对python感兴趣的人
💻 HTML
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>11.12 urlparse -- Parse URLs into components</title>
<META NAME="description" CONTENT="11.12 urlparse -- Parse URLs into components">
<META NAME="keywords" CONTENT="lib">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="STYLESHEET" href="lib.css" tppabs="http://www.python.org/doc/current/lib/lib.css">
<LINK REL="next" href="module-SocketServer.html" tppabs="http://www.python.org/doc/current/lib/module-SocketServer.html">
<LINK REL="previous" href="module-telnetlib.html" tppabs="http://www.python.org/doc/current/lib/module-telnetlib.html">
<LINK REL="up" href="internet.html" tppabs="http://www.python.org/doc/current/lib/internet.html">
<LINK REL="next" href="module-SocketServer.html" tppabs="http://www.python.org/doc/current/lib/module-SocketServer.html">
</head>
<body>
<DIV CLASS="navigation"><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="telnet-example.html" tppabs="http://www.python.org/doc/current/lib/telnet-example.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
  alt="Previous Page" width="32"></A></td>
<td><A href="internet.html" tppabs="http://www.python.org/doc/current/lib/internet.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
  alt="Up One Level" width="32"></A></td>
<td><A href="module-SocketServer.html" tppabs="http://www.python.org/doc/current/lib/module-SocketServer.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
  alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
  alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
  alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
  alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="telnet-example.html" tppabs="http://www.python.org/doc/current/lib/telnet-example.html">11.11.2 Telnet Example</A>
<b class="navlabel">Up:</b> <a class="sectref" href="internet.html" tppabs="http://www.python.org/doc/current/lib/internet.html">11. Internet Protocols and</A>
<b class="navlabel">Next:</b> <a class="sectref" href="module-SocketServer.html" tppabs="http://www.python.org/doc/current/lib/module-SocketServer.html">11.13 SocketServer  </A>
<br><hr></DIV>
<!--End of Navigation Panel-->

<H1><A NAME="SECTION00131200000000000000000">
11.12 <tt class="module">urlparse</tt> --
         Parse URLs into components</A>
</H1>

<P>

<P>


<P>
This module defines a standard interface to break Uniform Resource
Locator (URL) strings up in components (addressing scheme, network
location, path etc.), to combine the components back into a URL
string, and to convert a ``relative URL'' to an absolute URL given a
``base URL.''

<P>
The module has been designed to match the Internet RFC on Relative
Uniform Resource Locators (and discovered a bug in an earlier
draft!).

<P>
It defines the following functions:

<P>
<dl><dt><b><a name='l2h-2201'><tt class='function'>urlparse</tt></a></b> (<var>urlstring</var><big>[</big><var>, default_scheme</var><big>[</big><var>, allow_fragments</var><big>]</big><big>]</big>)
<dd>
Parse a URL into 6 components, returning a 6-tuple: (addressing
scheme, network location, path, parameters, query, fragment
identifier).  This corresponds to the general structure of a URL:
<code><var>scheme</var>://<var>netloc</var>/<var>path</var>;<var>parameters</var>?<var>query</var>#<var>fragment</var></code>.
Each tuple item is a string, possibly empty.
The components are not broken up in smaller parts (e.g. the network
location is a single string), and % escapes are not expanded.
The delimiters as shown above are not part of the tuple items,
except for a leading slash in the <var>path</var> component, which is
retained if present.

<P>
Example:

<P>
<dl><dd><pre class="verbatim">
urlparse('http://www.cwi.nl:80/%7Eguido/Python.html')
</pre></dl>

<P>
yields the tuple

<P>
<dl><dd><pre class="verbatim">
('http', 'www.cwi.nl:80', '/%7Eguido/Python.html', '', '', '')
</pre></dl>

<P>
If the <var>default_scheme</var> argument is specified, it gives the
default addressing scheme, to be used only if the URL string does not
specify one.  The default value for this argument is the empty string.

<P>
If the <var>allow_fragments</var> argument is zero, fragment identifiers
are not allowed, even if the URL's addressing scheme normally does
support them.  The default value for this argument is <code>1</code>.
</dl>

<P>
<dl><dt><b><a name='l2h-2202'><tt class='function'>urlunparse</tt></a></b> (<var>tuple</var>)
<dd>
Construct a URL string from a tuple as returned by <code>urlparse()</code>.
This may result in a slightly different, but equivalent URL, if the
URL that was parsed originally had redundant delimiters, e.g. a ? with
an empty query (the draft states that these are equivalent).
</dl>

<P>
<dl><dt><b><a name='l2h-2203'><tt class='function'>urljoin</tt></a></b> (<var>base, url</var><big>[</big><var>, allow_fragments</var><big>]</big>)
<dd>
Construct a full (``absolute'') URL by combining a ``base URL''
(<var>base</var>) with a ``relative URL'' (<var>url</var>).  Informally, this
uses components of the base URL, in particular the addressing scheme,
the network location and (part of) the path, to provide missing
components in the relative URL.

<P>
Example:

<P>
<dl><dd><pre class="verbatim">
urljoin('http://www.cwi.nl/%7Eguido/Python.html', 'FAQ.html')
</pre></dl>

<P>
yields the string

<P>
<dl><dd><pre class="verbatim">
'http://www.cwi.nl/%7Eguido/FAQ.html'
</pre></dl>

<P>
The <var>allow_fragments</var> argument has the same meaning as for
<code>urlparse()</code>.
</dl>

<P>
<div class='seealso'>
  <p class='heading'><b>See Also:</b></p>

  <dl compact class="seerfc">
    <dt><a href="javascript:if(confirm('http://www.ietf.org/rfc/rfc1738.txt  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://www.ietf.org/rfc/rfc1738.txt'" tppabs="http://www.ietf.org/rfc/rfc1738.txt"
        title="Uniform Resource Locators (URL)"
        >RFC 1738, <em>Uniform Resource Locators (URL)</em> <img src="offsite.gif" tppabs="http://www.python.org/doc/current/icons/offsite.gif"
  border='0' class='offsitelink' height='15' width='17' alt='[off-site link]'
  ></a>
    <dd>
        This specifies the formal syntax and semantics of absolute
        URLs.
  </dl>
  <dl compact class="seerfc">
    <dt><a href="javascript:if(confirm('http://www.ietf.org/rfc/rfc1808.txt  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://www.ietf.org/rfc/rfc1808.txt'" tppabs="http://www.ietf.org/rfc/rfc1808.txt"
        title="Relative Uniform Resource Locators"
        >RFC 1808, <em>Relative Uniform Resource Locators</em> <img src="offsite.gif" tppabs="http://www.python.org/doc/current/icons/offsite.gif"
  border='0' class='offsitelink' height='15' width='17' alt='[off-site link]'
  ></a>
    <dd>
        This Request For Comments includes the rules for joining an
        absolute and a relative URL, including a fair normal of
        ``Abnormal Examples'' which govern the treatment of border
        cases.
  </dl>
  <dl compact class="seerfc">
    <dt><a href="javascript:if(confirm('http://www.ietf.org/rfc/rfc2396.txt  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://www.ietf.org/rfc/rfc2396.txt'" tppabs="http://www.ietf.org/rfc/rfc2396.txt"
        title="Uniform Resource Identifiers (URI): Generic Syntax"
        >RFC 2396, <em>Uniform Resource Identifiers (URI): Generic Syntax</em> <img src="offsite.gif" tppabs="http://www.python.org/doc/current/icons/offsite.gif"
  border='0' class='offsitelink' height='15' width='17' alt='[off-site link]'
  ></a>
    <dd>
        Document describing the generic syntactic requirements for
        both Uniform Resource Names (URNs) and Uniform Resource
        Locators (URLs).
  </dl>
</div>

<DIV CLASS="navigation"><p><hr><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="telnet-example.html" tppabs="http://www.python.org/doc/current/lib/telnet-example.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
  alt="Previous Page" width="32"></A></td>
<td><A href="internet.html" tppabs="http://www.python.org/doc/current/lib/internet.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
  alt="Up One Level" width="32"></A></td>
<td><A href="module-SocketServer.html" tppabs="http://www.python.org/doc/current/lib/module-SocketServer.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
  alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
  alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
  alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
  alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="telnet-example.html" tppabs="http://www.python.org/doc/current/lib/telnet-example.html">11.11.2 Telnet Example</A>
<b class="navlabel">Up:</b> <a class="sectref" href="internet.html" tppabs="http://www.python.org/doc/current/lib/internet.html">11. Internet Protocols and</A>
<b class="navlabel">Next:</b> <a class="sectref" href="module-SocketServer.html" tppabs="http://www.python.org/doc/current/lib/module-SocketServer.html">11.13 SocketServer  </A>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>See <i><a href="about.html" tppabs="http://www.python.org/doc/current/lib/about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -