# -*- coding: UTF-8 -*-import requestsimport timeimport osfrom bs4 import BeautifulSouptitles = {}page = 3path = "http://findicons.com"response = requests.get("http://findicons.com/pack/" + str(page) + "")soup = BeautifulSoup(response.content, "html.parser")# 根据标题Key,详情页为内页for item in soup.select(".inner"): titles[item.select("a")[0]['title']] = path + item.select("a")[0]['href']for i in titles: dirName = i os.makedirs("img/" + dirName) path = titles[i] imgResponse = requests.get(path) soup = BeautifulSoup(imgResponse.content, "html.parser") for imgitem in soup.select(".iconenter"): imgurl = imgitem.select("img")[0]['src'] downImageResponse = requests.get(imgurl) if downImageResponse.status_code == 200: with open("img/" + dirName + "/" + str(time.time()) + ".png", "wb") as file: file.write(downImageResponse.content)复制代码