今天小编就为大家分享一篇python 3.3 下载固定链接文件并保存的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
python 3.3 下载固定链接文件并保存。
import urllib.request print ("downloading with urllib") url = 'http://www.wzsky.net/img2013/uploadimg/20130906/1216294.jpg-600' f = urllib.request.urlopen(url) data = f.read() with open("d:/color/1216294.jpg-600", "wb") as code: code.write(data)
urllib在3.3版本有了很大变化:
urllib.error: ContentTooShortError; HTTPError; URLError
urllib.parse: parse_qs; parse_qsl; quote; quote_from_bytes; quote_plus; unquote
unquote_plus; unquote_to_bytes; urldefrag; urlencode; urljoin; urlparse; urlsplit; urlunparse; urlunsplit
urllib.request: AbstractBasicAuthHandler; AbstractDigestAuthHandler; BaseHandler;
CatheFTPHandler; FTPHandler; FancyURLopener; FileHandler; HTTPBasicAuthHandler; HTTPCookieProcessor; HTTPDefaultErrorHandler; HTTPDigestAuthHandler; HTTPErrorProcessorl; HTTPHandler; HTTPPasswordMgr; HTTPPasswordMgrWithDefaultRealm; HTTPRedirectHandler; HTTPSHandler;OpenerDirector;ProxyBasicAuthHandler ProxyDigestAuthHandler; ProxyHandler; Request; URLopener; UnknowHandler; build_opener; getproxies; install_opener; pathname2url; url2pathname; urlc<div style="color:transparent">来源gaodai^.ma#com搞#代!码网</div>leanup; urlopen; urlretrieve;
urllib.response: addbase; addclosehook; addinfo; addinfourl;
urllib.robotparser: RobotFileParser
另外,这个方法对于有防盗链的链接只能下载到防盗链图片。
以上就是python 3.3 下载固定链接文件并保存的方法的详细内容,更多请关注gaodaima搞代码网其它相关文章!