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

📄 module-urllib.html

📁 一本很好的python的说明书,适合对python感兴趣的人
💻 HTML
📖 第 1 页 / 共 2 页
字号:
</dl>

<P>
<dl><dt><b><a name='l2h-1998'><tt class='function'>unquote</tt></a></b> (<var>string</var>)
<dd>
Replace "<tt class="samp">%xx</tt>" escapes by their single-character equivalent.

<P>
Example: <code>unquote('/%7Econnolly/')</code> yields <code>'/~connolly/'</code>.
</dl>

<P>
<dl><dt><b><a name='l2h-1999'><tt class='function'>unquote_plus</tt></a></b> (<var>string</var>)
<dd>
Like <tt class="function">unquote()</tt>, but also replaces plus signs by spaces, as
required for unquoting HTML form values.
</dl>

<P>
<dl><dt><b><a name='l2h-2000'><tt class='function'>urlencode</tt></a></b> (<var>dict</var>)
<dd>
Convert a dictionary to a ``url-encoded'' string, suitable to pass to
<tt class="function">urlopen()</tt> above as the optional <var>data</var> argument.  This
is useful to pass a dictionary of form fields to a <code>POST</code>
request.  The resulting string is a series of
<code><var>key</var>=<var>value</var></code> pairs separated by "<tt class="character">&amp;</tt>"
characters, where both <var>key</var> and <var>value</var> are quoted using
<tt class="function">quote_plus()</tt> above.
</dl>

<P>
The public functions <tt class="function">urlopen()</tt> and
<tt class="function">urlretrieve()</tt> create an instance of the
<tt class="class">FancyURLopener</tt> class and use it to perform their requested
actions.  To override this functionality, programmers can create a
subclass of <tt class="class">URLopener</tt> or <tt class="class">FancyURLopener</tt>, then assign
that an instance of that class to the
<code>urllib._urlopener</code> variable before calling the desired function.
For example, applications may want to specify a different
<code>user-agent</code> header than <tt class="class">URLopener</tt> defines.  This can be
accomplished with the following code:

<P>
<dl><dd><pre class="verbatim">
class AppURLopener(urllib.FancyURLopener):
    def __init__(self, *args):
        self.version = "App/1.7"
        apply(urllib.FancyURLopener.__init__, (self,) + args)

urllib._urlopener = AppURLopener()
</pre></dl>

<P>
<dl><dt><b><a name='l2h-2001'><tt class='class'>URLopener</tt></a></b> (<big>[</big><var>proxies</var><big>[</big><var>, **x509</var><big>]</big><big>]</big>)
<dd>
Base class for opening and reading URLs.  Unless you need to support
opening objects using schemes other than <span class="file">http:</span>, <span class="file">ftp:</span>,
<span class="file">gopher:</span> or <span class="file">file:</span>, you probably want to use
<tt class="class">FancyURLopener</tt>.

<P>
By default, the <tt class="class">URLopener</tt> class sends a
<code>user-agent</code> header of "<tt class="samp">urllib/<var>VVV</var></tt>", where
<var>VVV</var> is the <tt class="module">urllib</tt> version number.  Applications can
define their own <code>user-agent</code> header by subclassing
<tt class="class">URLopener</tt> or <tt class="class">FancyURLopener</tt> and setting the instance
attribute <tt class="member">version</tt> to an appropriate string value before the
<tt class="method">open()</tt> method is called.

<P>
Additional keyword parameters, collected in <var>x509</var>, are used for
authentication with the <span class="file">https:</span> scheme.  The keywords
<var>key_file</var> and <var>cert_file</var> are supported; both are needed to
actually retrieve a resource at an <span class="file">https:</span> URL.
</dl>

<P>
<dl><dt><b><a name='l2h-2002'><tt class='class'>FancyURLopener</tt></a></b> (<var>...</var>)
<dd>
<tt class="class">FancyURLopener</tt> subclasses <tt class="class">URLopener</tt> providing default
handling for the following HTTP response codes: 301, 302 or 401.  For
301 and 302 response codes, the <code>location</code> header is used to
fetch the actual URL.  For 401 response codes (authentication
required), basic HTTP authentication is performed.

<P>
The parameters to the constructor are the same as those for
<tt class="class">URLopener</tt>.
</dl>

<P>
Restrictions:

<P>

<UL>
<LI>Currently, only the following protocols are supported: HTTP, (versions
0.9 and 1.0), Gopher (but not Gopher-+), FTP, and local files.


<P>
</LI>
<LI>The caching feature of <tt class="function">urlretrieve()</tt> has been disabled
until I find the time to hack proper processing of Expiration time
headers.

<P>
</LI>
<LI>There should be a function to query whether a particular URL is in
the cache.

<P>
</LI>
<LI>For backward compatibility, if a URL appears to point to a local file
but the file can't be opened, the URL is re-interpreted using the FTP
protocol.  This can sometimes cause confusing error messages.

<P>
</LI>
<LI>The <tt class="function">urlopen()</tt> and <tt class="function">urlretrieve()</tt> functions can
cause arbitrarily long delays while waiting for a network connection
to be set up.  This means that it is difficult to build an interactive
web client using these functions without using threads.

<P>
</LI>
<LI>The data returned by <tt class="function">urlopen()</tt> or <tt class="function">urlretrieve()</tt>
is the raw data returned by the server.  This may be binary data
(e.g. an image), plain text or (for example) HTML.  The
HTTP protocol provides type information in the
reply header, which can be inspected by looking at the
<code>content-type</code> header.  For the Gopher
protocol, type information is encoded in the URL; there is currently
no easy way to extract it.  If the returned data is HTML, you can use
the module <tt class='module'><a href="module-htmllib.html" tppabs="http://www.python.org/doc/current/lib/module-htmllib.html">htmllib</a></tt> to parse it.

<P>
</LI>
<LI>This module does not support the use of proxies which require
authentication.  This may be implemented in the future.

<P>
</LI>
<LI>Although the <tt class="module">urllib</tt> module contains (undocumented) routines
to parse and unparse URL strings, the recommended interface for URL
manipulation is in module <tt class='module'><a href="module-urlparse.html" tppabs="http://www.python.org/doc/current/lib/module-urlparse.html">urlparse</a></tt>.

<P>
</LI>
</UL>

<P>

<p><hr>
<!--Table of Child-Links-->
<A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></A>

<UL>
<LI><A NAME="tex2html3908"
  href="urlopener-objs.html" tppabs="http://www.python.org/doc/current/lib/urlopener-objs.html">11.3.1 URLopener Objects </A>
<LI><A NAME="tex2html3909"
  href="Urllib_Examples.html" tppabs="http://www.python.org/doc/current/lib/Urllib_Examples.html">11.3.2 Examples</A>
</UL>
<!--End of Table of Child-Links-->

<DIV CLASS="navigation"><p><hr><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A HREF="node247.html" tppabs="http://www.python.org/doc/current/lib/node247.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="urlopener-objs.html" tppabs="http://www.python.org/doc/current/lib/urlopener-objs.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="node247.html" tppabs="http://www.python.org/doc/current/lib/node247.html">11.2.9 Common problems and</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="urlopener-objs.html" tppabs="http://www.python.org/doc/current/lib/urlopener-objs.html">11.3.1 URLopener Objects</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 + -