Python3抓取网页图片
2017-01-26 14:13
323 查看
# -*- coding: utf-8 -*- # @Author: Mayuko # @Date: 2017-01-24 15:09:23 # @Last Modified by: Mayuko # @Last Modified time: 2017-01-26 14:09:06 import urllib.request import socket import re import sys import os import math targetDir = r"D:\images" 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://vscom.mayuko.cn/" req = urllib.request.Request(hostname) webpage = urllib.request.urlopen(req) contentBytes = webpage.read() for link, t in set(re.findall(r'(http://[^\s]*?(jpg))', str(contentBytes))): print("Cache the images of " + link) urllib.request.urlretrieve(link, destFile(link)) print("Cache done")
相关文章推荐
- Python3 抓取网页中的图片
- python抓取网页图片
- python抓取网页图片 python爬虫实例
- 使用Python3编写抓取网页和只抓网页图片的脚本
- Python抓取给定URL网页里的图片
- 使用Python抓取网页图片[转载]
- python抓取网页图片示例(python爬虫)
- 黄聪:python访问抓取网页常用命令(保存图片到本地、模拟POST、GET、中文编码问题)
- Python -- 网络编程 -- 抓取网页图片 -- 豆瓣妹子
- 使用Python3编写抓取网页和只抓网页图片的脚本
- python抓取网页图片
- python抓取网页中的图片示例
- python抓取网页图片并放到指定文件夹
- Python3 抓取网页中的图片
- python抓取网页图片
- python抓取网页图片
- Python抓取网页图片
- python抓取网页中图片并保存到本地
- python抓取网页图片
- python网络爬虫,抓取网页图片