python爬虫 | 您所在的位置:网站首页 › 虎牙美女加特林谁最好看啊 › python爬虫 |
长按点赞,等你来干!!! 目录 爬虫百度人脸识别接口效果演示 爬虫网页链接:https://www.huya.com/g/4079 这里的主要步骤其实还是和我们之前分析的一样,如下图所示: 这样我们就能获取到我们所需要的所有资源,之后将图片保存下来即可。这其中有两种文件的下载方式,一种是通过 with open打开文件的方式 ,另外一种就是通过 urllib.request.urlretrieve(data,path) 的方法,网上说第二种方式的下载速度会相对快一点,并且第二种有点 set 集合的意思,可以自动进行 去重 的操作,下载的文件夹中没有该文件就下载,否则就跳过。 #保存主播头像 def download(datalist): for data in datalist: #第一种下载方式 with open("D:/software/python/python爬虫/虎牙颜值主播排名/", 'wb') as f: f.write(data[0]) #第二种下载方式 urllib.request.urlretrieve(data[0],"D:/software/python/python爬虫/虎牙颜值主播排名"+"/"+data[1]+".jpg") print(data[1]+"下载完成") 百度人脸识别接口百度AI开放平台链接:https://ai.baidu.com/
之后我们就只需要编写一个遍历文件夹下面的图片进行检测,之后将整个信息按照颜值分数进行降序排列: path=r"D:\software\python\python爬虫\虎牙颜值主播排名" image_list=os.listdir(path) name_score={} for image in image_list: try: print(image.split(".")[0]+"颜值评分为:%d"%face_rg(path+"/"+image)) name_score[image.split(".")[0]]=face_rg(path+"/"+image) except: pass second_score=sorted(name_score.items(),key=lambda x:x[1],reverse=True) print("-------------------------------------检测结束-------------------------------------") print("-------------------------------------以下是排名-------------------------------------") for a,b in enumerate(second_score): print("{}的颜值评分为:{},排名第{}".format(second_score[a][0],second_score[a][1],a+1))这里博主测完自己的颜值是 52分,连及格线都没到 ,大家也可以在评论区说说自己的分数。
我的博客即将同步至腾讯云+社区,邀请大家一同入驻:https://cloud.tencent.com/developer/support-plan?invite_code=1ajy6jg72g6nq |
CopyRight 2018-2019 实验室设备网 版权所有 |