try:
img_url = info.xpath(‘div[1]/div[2]/img/@data-original-src’)[0]
print(img_url)
data = requests.get(‘http:’ + img_url,headers=headers)
try:
fp = open(‘row_img/’ + title + ‘+’ + name + ‘+’ + str(i) + ‘.jpg’,‘wb’)
fp.write(data.content)
fp.close()
except OSError:
fp = open(‘row_img/’ + name + ‘+’ + str(i) + ‘.jpg’, ‘wb’)
fp.write(data.content)
fp.close()
except IndexError:
pass
i = i + 1
if name == ‘main’:
urls = [‘https://www.jianshu.com/c/bd38bd199ec6?order_by=added_at&page={}’.format(str(i)) for i in range(1,201)]
for url in urls:
get_url(url)
由于爬取了帖子下面的所有图片,里面有各种图片(不包括人脸),而且是为了找到高颜值小姐姐,如果人工筛选费事费力,这里调用百度的人脸识别API,进行图片过滤和颜值打分。
人脸识别应用申请
首先,进入百度人脸识别官网,点击立即使用,登陆百度账号(没有就注册一个)。
创建应用,完成后,点击管理应用,就能看到AppID等,这些在调用API时需要使用的。
API调用
这里使用杨超越的图片先试下水。通过结果,可以看到75分,还算比较高了(自己用了一些网红和明星测试了下,分数平均在80左右,最高也没有90以上的)。
from aip import AipFace
import base64
APP_ID = ‘’
API_KEY = ‘’
SECRET_KEY = ‘’
aipFace = AipFace(APP_ID, API_KEY, SECRET_KEY)
filePath = r’C:\Users\LP\Desktop\6.jpg’
def get_file_content(filePath):
with open(filePath, ‘rb’) as fp:
content = base64.b64encode(fp.read())
return content.decode(‘utf-8’)
imageType = “BASE64”
options = {}
options[“face_field”] = “age,gender,beauty”
result = aipFace.detect(get_file_content(filePath),imageType,options)
print(result)
最后结合图片数据和颜值打分,设计代码,过滤掉非人物以及男性图片,获取小姐姐图片的分数(这里处理为1-10分),并分别存在不同的文件夹中。
from aip import AipFace
import base64
import os
import time
APP_ID = ‘’
API_KEY = ‘’
SECRET_KEY = ‘’
aipFace = AipFace(APP_ID, API_KEY, SECRET_KEY)
def get_file_content(filePath):
with open(filePath, ‘rb’) as fp:
content = base64.b64encode(fp.read())
return content.decode(‘utf-8’)
imageType = “BASE64”
options = {}
options[“face_field”] = “age,gender,beauty”
file_path = ‘row_img’
file_lists = os.listdir(file_path)
for file_list in file_lists:
result = aipFace.detect(get_file_content(os.path.join(file_path,file_list)),imageType,options)
error_code = result[‘error_code’]
if error_code == 222202:
continue
try:
sex_type = result[‘result’][‘face_list’][-1][‘gender’][‘type’]
if sex_type == ‘male’:
continue
print(result)
beauty = result[‘result’][‘face_list’][-1][‘beauty’]
new_beauty = round(beauty/10,1)
print(file_list,new_beauty)
if new_beauty >= 8:
os.rename(os.path.join(file_path,file_list),os.path.join(‘8分’,str(new_beauty) + ‘+’ + file_list))
elif new_beauty >= 7:
os.rename(os.path.join(file_path,file_list),os.path.join(‘7分’,str(new_beauty) + ‘+’ + file_list))
(1)Python所有方向的学习路线(新版)
这是我花了几天的时间去把Python所有方向的技术点做的整理,形成各个领域的知识点汇总,它的用处就在于,你可以按照上面的知识点去找对应的学习资源,保证自己学得较为全面。
最近我才对这些路线做了一下新的更新,知识体系更全面了。
(2)Python学习视频
包含了Python入门、爬虫、数据分析和web开发的学习视频,总共100多个,虽然没有那么全面,但是对于入门来说是没问题的,学完这些之后,你可以按照我上面的学习路线去网上找其他的知识资源进行进阶。
(3)100多个练手项目
我们在看视频学习的时候,不能光动眼动脑不动手,比较科学的学习方法是在理解之后运用它们,这时候练手项目就很适合了,只是里面的项目比较多,水平也是参差不齐,大家可以挑自己能做的项目去练练。
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!