python爬虫-图片批量下载
# 爬起摄图网的图片批量下载
# coding:utf-8 import requests from bs4 import BeautifulSoup from scipy.misc import imresize import numpy as np import os # 我们下载摄图网的10个种类图片 climbImage = requests.get( # url = 'http://699pic.com/tupian/photo-houzi.html' url = 'http://699pic.com/photo-184430-0-2-0-0-0.html' ) climbImage.encoding = climbImage.apparent_encoding soup = BeautifulSoup(climbImage.text,features='lxml') # text = soup.find(id = 'wrapper') div_text = soup.find_all(class_='list') n = 0 classname =9 # 种类的名字 for i in div_text: a = i.find('a') if a: # print(a) img = a.find('img') # print(img) img_url = img.attrs.get('data-original') image = requests.get(img_url) # img_size = imresize(np.array(image.content),[100,100]) imgname = '0_'+str(n)+'.jpg' if os.path.exists('./data/%s'%classname) == False: os.mkdir('./data/%s' % classname) with open('data/%s/'%classname + imgname, 'wb') as f: f.write(image.content) n+=1
自动化学习。