Python3 抓取网页中的图片
来源:互联网 发布:淘宝宝贝主图素材 编辑:程序博客网 时间:2024/04/30 20:37
import urllib.requestimport socketimport reimport sysimport ostargetDir = r"C:\Users\elqstux\Desktop\pic"def destFile(path): if not os.path.isdir(targetDir): os.mkdir(targetDir) pos = path.rindex('/') t = os.path.join(targetDir, path[pos+1:]) return tif __name__ == "__main__": hostname = "http://www.douban.com" req = urllib.request.Request(hostname) webpage = urllib.request.urlopen(req) contentBytes = webpage.read() for link, t in set(re.findall(r'(http:[^\s]*?(jpg|png|gif))', str(contentBytes))): print(link) urllib.request.urlretrieve(link, destFile(link))
import urllib.requestimport socketimport reimport sysimport ostargetDir = r"H:\pic"def destFile(path): if not os.path.isdir(targetDir): os.mkdir(targetDir) pos = path.rindex('/') t = os.path.join(targetDir, path[pos+1:]) #会以/作为分隔 return tif __name__ == "__main__": hostname = "http://www.douban.com/" req = urllib.request.Request(hostname) webpage = urllib.request.urlopen(req) contentBytes = webpage.read() match = re.findall(r'(http:[^\s]*?(jpg|png|gif))', str(contentBytes) )#r'(http:[^\s]*?(jpg|png|gif))'中包含两层圆括号,故有两个分组, #上面会返回列表,括号中匹配的内容才会出现在列表中 for picname, picType in match: print(picname) print(picType) '''输出:http://img3.douban.com/pics/blank.gifgifhttp://img3.douban.com/icon/g111328-1.jpgjpghttp://img3.douban.com/pics/blank.gifgifhttp://img3.douban.com/icon/g197523-19.jpgjpghttp://img3.douban.com/pics/blank.gifgif...'''
转载来源:http://blog.csdn.net/wangyangkobe/article/details/8712121
0 0
- Python3 抓取网页中的图片
- Python3 抓取网页中的图片
- Python3抓取网页图片
- Python3.4.4抓取网页图片
- python3 抓取网页自有图片
- Python3简单爬虫抓取网页图片
- Python3下载网页中的图片
- Python3网页抓取urllib
- 怎样抓取网页中的图片地址呢?
- 简单的抓取网页中的图片
- Python3.6中的简单抓取百度网页源代码
- Python3抓取页面图片
- python3抓取百度图片
- Python3.0 如何抓取网页
- 用python3抓取中文网页
- Python3:抓取网页HTML代码
- python3.x 抓取网页资源
- python3爬虫--抓取网页信息
- 初创企业为何多以失败告终
- .net reactor 学习系列(三)---.net reactor代码自动操作相关保护功能
- 操作系统(二)—— 进程 & 程序 & 线程
- qq最新侧滑效果实现
- 巴菲特致股东的一封信:2012年 和学习心得
- Python3 抓取网页中的图片
- 自定义UISlider的样式和滑块 [转]
- UIProgressView的详细使用
- 黑马程序员__泛型
- UIImage 详解
- UITableView的协议
- win7/ubuntu双系统安装(安装ubuntu黑屏后光标一直闪)
- 439 - Knight Moves(bfs)
- android应用程序安装位置分析