mirror of
https://github.com/kennethreitz/dive-into-python3.git
synced 2026-06-05 23:10:17 +00:00
grr
This commit is contained in:
@@ -59,7 +59,8 @@ mark{display:inline}
|
||||
<id>tag:diveintomark.org,2001-07-29:/</id>
|
||||
<updated>2009-03-27T21:56:07Z</updated>
|
||||
<link rel="alternate" type="text/html" href="http://diveintomark.org/"/>
|
||||
<-- rest of feed omitted for brevity --></samp></pre>
|
||||
…
|
||||
</samp></pre>
|
||||
<ol>
|
||||
<li>Downloading anything over HTTP is incredibly easy in Python; in fact, it’s a one-liner. The <code>urllib.request</code> module has a handy <code>urlopen()</code> function that takes the address of the page you want, and returns a file-like object that you can just <code>read()</code> from to get the full contents of the page. It just can’t get any easier.
|
||||
</ol>
|
||||
@@ -341,7 +342,8 @@ class DefaultErrorHandler(urllib2.HTTPDefaultErrorHandler): <span>①</s
|
||||
xml:lang="en">
|
||||
<title mode="escaped">dive into mark</title>
|
||||
<link rel="alternate" type="text/html" href="http://diveintomark.org/"/>
|
||||
<-- rest of feed omitted for brevity --></samp>
|
||||
…
|
||||
</samp>
|
||||
<samp class=p>>>> </samp><kbd>request.add_header('If-None-Match',</kbd>
|
||||
<samp class=p>... </samp>firstdatastream.headers.get('ETag')) <span>③</span>
|
||||
<samp class=p>>>> </samp><kbd>seconddatastream = opener.open(request)</kbd>
|
||||
@@ -602,7 +604,8 @@ header: Content-Type: application/atom+xml</span>
|
||||
xml:lang="en">
|
||||
<title mode="escaped">dive into mark</title>
|
||||
<link rel="alternate" type="text/html" href="http://diveintomark.org/"/>
|
||||
<-- rest of feed omitted for brevity --></samp>
|
||||
…
|
||||
</samp>
|
||||
<samp class=p>>>> </samp><kbd>len(data)</kbd>
|
||||
15955
|
||||
</pre>
|
||||
@@ -711,7 +714,8 @@ def fetch(source, etag=None, last_modified=None, agent=USER_AGENT):
|
||||
'status': 301,
|
||||
'data': '<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<feed version="0.3"
|
||||
<-- rest of data omitted for brevity -->'}</samp>
|
||||
…
|
||||
'}</samp>
|
||||
<samp class=p>>>> </samp><kbd>if params['status'] == 301:</kbd><span>③</span>
|
||||
<samp class=p>... </samp>url = params['url']
|
||||
<samp class=p>>>> </samp><kbd>newparams = openanything.fetch(</kbd>
|
||||
|
||||
Reference in New Issue
Block a user