圆月山庄资源网 Design By www.vgjia.com

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,3.3,链接,文件,保存

圆月山庄资源网 Design By www.vgjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
圆月山庄资源网 Design By www.vgjia.com