使用python进行爬虫下载指定网站的图片

# coding=utf-8

import urllib
import re


def downloadPage(url):
    h = urllib.urlopen(url)
    return h.read()


def downloadImg(content):
    pattern = r'src="(.+?\.jpg)" alt' #正则匹配图片标签
    m = re.compile(pattern)
    urls = re.findall(m, content)

    for i, url in enumerate(urls):
        urllib.urlretrieve(url, "E:\\222222\\%s.jpg" % (i,)) #图片保存地址


content = downloadPage("http://www.ivsky.com/tupian/meimei_de_fengye_v39839") #图片下载地址
downloadImg(content)

  

posted @ 2017-04-01 09:13  my_paradise  阅读(402)  评论(0编辑  收藏  举报