下载png图标素材II

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

import os
import re
import urllib.request

key = ["code","help","about", "close"] #需要下载的图标素材关键字
min = 16  #min size
max = 16  #max size
home = "http://www.easyicon.net/"
down = "http://download.easyicon.net/"
#url = home + "iconsearch/" + key + "/&min=" + str(min) + "&max=" + str(max)
down_list = False       # down more
def downimg(url, k):
    try:
        page = urllib.request.urlopen(url).read()
        page = page.decode("utf-8")
        #print(page)
        
        #s_key = r'src="(.+?\.gif)"'
        s_key = r'href="(' + down + '.+?)"'
        rec = re.compile(s_key)
        l = re.findall(rec, page)    
        
        print(len(l))
        i = 0
        for img in l:
            i += 1
            try:
                
                s1 = img.split("/")
                s_type = s1[3]
                s_name = s1[4]
                s_size = s1[5]
                #print(s_type + " " + s_name + " " + s_size)
                if s_type != "ico" and s_type != "png":
                    continue
                
                print("(" + str(i) + "/" + str(len(l)) + ") " + img)
                if not os.path.exists(k):
                    os.makedirs(k)
                name = k + "/" + k + "_" + s_name + "_" + s_size + "." + s_type
                if not os.path.exists(name):
                    urllib.request.urlretrieve(img, name)
                
            except:
                print("Save File Error!")
            
        
        # down more
        if not down_list: 
            return
        
        s_key = r'href="(/iconsearch/.+?max\=' + str(max) + ')"'
        rec = re.compile(s_key)
        l = re.findall(rec, page)
        l2 = []
        for p in l:
            #print(p)
            b = False
            for p2 in l2:
                if p == p2:
                    b = True
            if not b:
                l2.append(home + p[1:])
                print(home + p[1:])
                downimg(home + p[1:], k)
    except:
        print("Error!")


if __name__ == "__main__":
    for k in key:
        url = home + "iconsearch/" + k + "/&min=" + str(min) + "&max=" + str(max)
        print(k)
        downimg(url, k)