爬取校花网美眉图

#Author:Elson Zeng
import os
import requests
import re


# http://www.xiaohuar.com/list-1-1.html
# http://www.xiaohuar.com/list-1-2.html
#mg width="210" alt="台湾朝阳科技大学校花陈静怡" src="/d/file/20181113/f957a341bd5ff1dd62641494ce6db464.jpg">

urls = 'http://www.xiaohuar.com/list-1-%s.html' path = 'C:/Users/JIAN/Desktop/python_dowload/'+ 'MM' + '/' for i in range(1000): temp = urls %i response = requests.get(temp) html = response.text girl_urls = re.findall(r'/d/file/\d+/\w+\.jpg',html) #girl_name = re.findall(r'/d/file/\d+/\w+\.jpg', html) for girl_url in girl_urls: img_url = requests.get('http://www.xiaohuar.com'+ girl_url) img_data = img_url.content girl_name = girl_url.split('/')[-1] girl_path = path + girl_name if not os.path.exists(path): os.mkdir(path) if not os.path.exists(girl_path): with open(girl_path,'wb') as f: f.write(img_data)

 

posted @ 2019-05-04 12:21  One只自大猫丶  阅读(903)  评论(0编辑  收藏  举报