python 3.3 下载固定链接文件并保存的方法

yipeiwu_com6年前Python基础

python 3.3 下载固定链接文件并保存。

import urllib.request
print ("downloading with urllib")
url = '/zb_users/upload/202003/5cvdswfybfa.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设计】。

相关文章

python实现定时发送qq消息

python实现定时发送qq消息

因为生活中老是忘记各种事情,刚好又在学python,便突发奇想通过python实现提醒任务的功能(尽管TIM有定时功能),也可定时给好友、群、讨论组发送qq消息。其工作流程是:访问数据库...

浅谈python 中类属性共享的问题

感觉这种理解有问题,举个例子来说。 class Dog(object): name = 'dog' def init(self): self.age...

python的concat等多种用法详解

本文为大家分享了python的concat等多种用法,供大家参考,具体内容如下 1、numpy中的concatenate()函数: >>> a = np.array...

详解python中的hashlib模块的使用

hashlib hashlib主要提供字符加密功能,将md5和sha模块整合到了一起,支持md5,sha1, sha224, sha256, sha384, sha512等算法 hash...

Django中的文件的上传的几种方式

PS:这段时间有点不在状态,刚刚找回那个状态,那么我们继续曾经的梦想 今天我们来补充一下文件的上传的几种方式: 首先我们先补充的一个知识点: 一、请求头ContentType: Con...