首页 > 代码库 > python3下载图片
python3下载图片
import urllib.request import socket import re import sys import os targetDir = r"E:\\DATA\常用py脚本" def destFile(path): if not os.path.isdir(targetDir): os.mkdir(targetDir) pos = path.rindex(‘/‘) t = os.path.join(targetDir, path[pos+1:]) return t if __name__ == "__main__": hostname = "http://www.douban.com" req = urllib.request.Request(hostname) webpage = urllib.request.urlopen(req) html = webpage.read() #\s:任意空白字符 #^:匹配字符串的开头 #*:匹配前一个字符0次或无数次 #?:匹配前一个字符0次或1次 result=re.findall(r‘(https:[^\s]*?(jpg|png|gif))‘, str(html)) #print(result) for link, t in result: #print(link,t) urllib.request.urlretrieve(link, destFile(link))
python3下载图片
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。