1
Related Articles
Python
•
Python
urllib.request URL Python urlopen
URL
cookies handlers opener
urllib.request ”URL ” URL ":" URL
"ftp://python.org/"` ``"ftp"` FTP HTTP
URL HTTP
For straightforward situations urlopen is very easy to use. But as soon as you encounter errors or non-trivial cases
when opening HTTP URLs, you will need some understanding of the HyperText Transfer Protocol. The most com-
prehensive and authoritative reference to HTTP is RFC 2616. This is a technical document and not intended to be
easy to read. This HOWTO aims to illustrate using urllib, with enough detail about HTTP to help you through. It is
not intended to replace the urllib.request docs, but is supplementary to them.
2 URL
urllib.request
import urllib.request
with urllib.request.urlopen('http://python.org/') as response:
html = response.read()
URL shutil.copyfileobj()
tempfile.NamedTemporaryFile() :
import shutil
import tempfile
import urllib.request
with urllib.request.urlopen('http://python.org/') as response:
with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
shutil.copyfileobj(response, tmp_file)
with open(tmp_file.name) as html:
pass
urllib URL ’http:’ ’ftp:’ ’file:’
HTTP
HTTP urllib.request HTTP
“Request“ Request URL Request
“urlopen“ URL
“.read()“
import urllib.request
req = urllib.request.Request('http://www.voidspace.org.uk')
( )
2
微信搜索公众号 "Python编程时光" ,回复 "pycharm" 获取免安装永久破解的专业版PyCharm
评论