博主上次看到暮光博客上 把他们学校的照片都download下来了。
于是,博主觉得.....爬下来看看漂亮妹纸的照片好像是个不错的主意啊.......
原始人类的本能(/▽\=)
爬取照片
这个......我们学校的做太烂了。。。连外网都可以直接爬。。。
怕被请去喝茶,特地SS全局下抓,然而速度慢,后面直接校内网上了=v=
轻轻松松的爬了下来,要注意的就是不知道一个班级人数和一个年级的班级,还有一个院的专业人数。
所以要进行试探。
不放代码,以防不良影响。
性别判断
对于男女比例7:3的学校来说。。。。。你让我一个个看。。。看到的都是汉纸,这不是坑爹么!!(╯-_-)╯╧╧
哥哥懒得看。 于是....男同胞们。。。你们要被发配到另一个文件夹。。。。。
性别判断用啥好呢~~~自己实现一个天都黑了,估计达到一定的精度还得一段时间。
FACE ++ 有API
注册一个就可以用了~
当然还有一些刷脸失败的  →_→ 移动到error里面吧。
ps: 存在一些误判,比如把一些妹纸当作汉纸对待了,还有一些刷脸失败的,这里存在以下假设
- 好看的妹纸应该是女性特征分明的 ,所以误判的妹纸......
- 好看的妹纸刷脸必须成功
 
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 
 | from facepp import API, Fileimport shutil
 import os
 
 if __name__ == '__main__':
 API_KEY = ''
 API_SECRET = ''
 api = API(API_KEY, API_SECRET)
 photo_path = r'G:/photos/'
 
 for path, subdirs, files in os.walk(photo_path):
 print path, subdirs, files
 if path.find('man') != -1 or path.find('error') != -1: continue
 for img in files:
 print path + '/' + img
 try:
 result = api.detection.detect(img=File(path + '/' + img), mode='oneface')
 if result['face'][0]['attribute']['gender']['value'] == 'Male':
 man_path = path + '/man'
 if not os.path.exists(man_path):
 os.mkdir(man_path)
 shutil.move(path + '/' + img, man_path + '/' + img)
 except Exception, e:
 error_path = path + '/error'
 if not os.path.exists(error_path):
 os.mkdir(error_path)
 shutil.move(path + '/' + img, error_path + '/' + img)
 
 | 
 
颜值打分
剩下还有一堆妹纸!!! 博主看得眼镜都花了。
决定应该提高门槛,让机器筛选,只看达到一定的颜值的妹纸
So如下计划:先给一些照片打好分数作为训练样本...抽出关键点作为特征....训练之........打分..........
等做好了哥哥都 看完了。。。= =
那怎么办呢。
听说最近 Microsoft 那只很 嚣张的小冰又升级了,上面有拼颜值功能 : http://kan.msxiaobing.com/V3/Portal
 ms-xiaoice-yanzhi
ms-xiaoice-yanzhi
虽然说是叫拼颜值,然而单人的情况会直接打分:如下
 ms-xiaoice-yanzhi-guanyuan-meizhi
ms-xiaoice-yanzhi-guanyuan-meizhi
在抓包、分析JS后轻易的可以伪装正常用户进行功能请求:
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 
 | 
 
 
 import json
 import re
 import requests
 import time
 import os, shutil
 
 if __name__ == '__main__':
 myheader = {
 'Host': 'kan.msxiaobing.com',
 'Connection': 'keep-alive',
 'Accept': '*/*',
 'Origin': 'http://kan.msxiaobing.com',
 'X-Requested-With': 'XMLHttpRequest',
 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.73 Safari/537.36',
 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
 'Referer': 'http://kan.msxiaobing.com/V3/Portal',
 'Accept-Encoding': 'gzip, deflate',
 'Accept-Language': 'zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.4',
 }
 
 url1 = 'http://kan.msxiaobing.com/Api/Image/UploadBase64'
 url2 = 'http://kan.msxiaobing.com/Api/ImageAnalyze/Process?service=yanzhi&tid=52a90c91aaeb4af698bec8ae2106cb36'
 
 pattern = re.compile(r'\d+\.\d+')
 s = requests.Session()
 
 photo_path = 'G:/photos'
 for path, subdirs, files in os.walk(photo_path):
 print path, subdirs, files
 if path.find('man') != -1 or path.find('error') != -1 or path.find('beautiful') != -1: continue
 for img in files:
 
 with open(path + '/' + img, 'rb') as f:
 image_data = f.read()
 image_data = image_data.encode("base64")
 
 try:
 r = s.post(url1, data=image_data, headers=myheader)
 res = json.loads(r.text)
 data = {
 'msgId': int(round(time.time() * 1000)),
 'timestamp': int(time.time()),
 'senderId': 'mtuId' + str(int(round(time.time() * 1000))),
 'content[imageUrl]': res['Host'] + res['Url']
 }
 
 r = s.post(url2, data=data, headers=myheader)
 res = json.loads(r.text)
 match = pattern.search(res['content']['text'])
 score = float(match.group())
 print path + '/' + img, score
 if score >= 7.0:
 beautiful_path = path + '/beautiful'
 if not os.path.exists(beautiful_path):
 os.mkdir(beautiful_path)
 shutil.move(path + '/' + img, beautiful_path + '/' + img)
 
 except Exception, e:
 error_path = path + '/ice_error'
 if not os.path.exists(error_path):
 os.mkdir(error_path)
 shutil.move(path + '/' + img, error_path + '/' + img)
 
 
 | 
 
写在最后
=v= 博主都大四旺了,也就看看妹纸就好。。。。。
不要问我图在哪,上面那两图就是其中的。  (/▽\=) 逃
= =禽兽舍友前来围观,博主发现这么晚了衣服都还没洗。。。
楼上的妹纸们中午动静好大,这是穿着高跟鞋在宿舍里乱跑么。。。
 expression-louxia_shuai
expression-louxia_shuai
吵了我们一中午。。。。→_→ 我觉得再吵应该派舍友去和她们谈谈人生理想 : )
嗯,睡觉。