python 3.3 下載固定鏈接文件并保存的方法
python 3.3 下載固定鏈接文件并保存。
import urllib.request
print ("downloading with urllib")
url = 'http://www.wzsky.net/img2013/uploadimg/20130906/1216294.jpg'
f = urllib.request.urlopen(url)
data = f.read()
with open("d:/color/1216294.jpg", "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; urlcleanup; urlopen; urlretrieve;
urllib.response: addbase; addclosehook; addinfo; addinfourl;
urllib.robotparser: RobotFileParser
另外,這個方法對于有防盜鏈的鏈接只能下載到防盜鏈圖片。
以上這篇python 3.3 下載固定鏈接文件并保存的方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
python-django中的APPEND_SLASH實現方法
這篇文章主要介紹了python-django中的APPEND_SLASH實現方法,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-06-06

