Python爬取《创造营2020》小姐姐数据用腾讯云人脸识别做颜值评分

最近 创造营2020好多小姐姐吸引到我了,于是就有这这个

Python爬取《创造营2020》小姐姐数据用腾讯云人脸识别做颜值评分_第1张图片

颜值100分的小姐姐高达21位比如前段时间抖音很火的 凡凡

Python爬取《创造营2020》小姐姐数据用腾讯云人脸识别做颜值评分_第2张图片

以下是代码,需要你在申请腾讯云有关参数替换哦

# -*- coding: utf-8 -*-
"""
Created on Sun May 24 20:45:13 2020

@author: Gdc
"""

import requests
from fake_useragent import UserAgent
import pandas as pd
import json
from lxml import etree

from tencentcloud.common import credential
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException 
from tencentcloud.iai.v20180301 import iai_client, models 

#腾讯云人脸检测与分析
#检测给定图片中的人脸(Face)的位置、相应的面部属性和人脸质量信息
#位置包括 (x,y,w,h)
#面部属性包括性别(gender)、年龄(age)、表情(expression)、魅力(beauty)、眼镜(glass)、发型(hair)、口罩(mask)和姿态 (pitch,roll,yaw)
#人脸质量信息包括整体质量分(score)、模糊分(sharpness)、光照分(brightness)和五官遮挡分(completeness)

def faceScore(url):
    try: 
        cred = credential.Credential("你的key", "你的id") 
        httpProfile = HttpProfile()
        httpProfile.endpoint = "iai.tencentcloudapi.com"
    
        clientProfile = ClientProfile()
        clientProfile.httpProfile = httpProfile
        client = iai_client.IaiClient(cred, "ap-beijing", clientProfile) 
    
        req = models.DetectFaceRequest()
        param = {"Url":url,"NeedFaceAttributes":1}
        params = json.dumps(param)
        req.from_json_string(params)
    
        resp = client.DetectFace(req) 
        respstr = resp.to_json_string().replace('false','0').replace('true','1')
        respdic = eval(respstr)
        
        age = respdic['FaceInfos'][0]['FaceAttributesInfo']['Age']
        beauty = respdic['FaceInfos'][0]['FaceAttributesInfo']['Beauty']
        
    except TencentCloudSDKException as err: 
        print(err)
    
    return age,beauty


url = 'https://zbaccess.video.qq.com/fcgi/getVoteActityRankList?'

headers = {"User-Agent": UserAgent(verify_ssl=False).random}

params = {'raw': 1,
           'vappid': 51902973,
           'vsecret': '14816bd3d3bb7c03d6fd123b47541a77d0c7ff859fb85f21',
           'actityId': 107015,
           'pageSize': 101,
           'vplatform': 3,
           'listFlag': 0,
           'pageContext':'' ,
           'ver': 1,
           '_t': 1590324974706,
           '_': 1590324974708
    }
re = requests.get(url,headers = headers,params = params)

data = json.loads(re.text)

Li_list = data['data']['itemList']
rank = 0
data_list = []

#获取每个选手的基础信息
for li in Li_list:
    rank += 1
    item = {}
    #获取基础信息
    item['当前排名'] = rank
    item['选手编号'] = li['itemInfo']['id']
    item['选手姓名'] = li['itemInfo']['name']
    item['选手照片'] = li['itemInfo']['mapData']['poster_pic']
    item['选手状态'] = li['statusInfo']['voteBtnTxt']
    
    #获取选手doki页
    #根据选手编号id到选手doki页面获取粉丝数、星座、身高、生日等基础个人信息
    #简单的静态页面,这里用到xpath做解析
    id_ = item['选手编号']
    url_ = f'https://v.qq.com/x/star/{id_}?tabid=2'
    re_ = requests.get(url_,headers = headers)
    re_.encoding='utf-8'
    html = etree.HTML(re_.text)
    item['粉丝数'] = html.xpath('.//div[@class="followers_count"]/text()')[0]
    info = html.xpath('.//div[@class="wiki_info_1"]//span[@class="content"]/text()')
    item['星座'] = info[-5]
    item['身高'] = info[-3]
    item['体重'] = info[-2]
    item['出生地'] = info[-1]
    info2 = html.xpath('.//div[@class="wiki_info_2"]//span[@class="content"]/text()')
    item['生日'] = info2[0]
    url_ai = item['选手照片']
    age,beauty = faceScore(url_ai) 
    item['AI预测年龄'] = age
    item['AI颜值评分'] = beauty
    data_list.append(item)


df = pd.DataFrame(data_list)
df.to_excel(r'D:\python\创造营\创造营2020名单.xlsx',sheet_name='名单',index=0)

 

源码分享在文章里了   你觉得哪个小姐姐最好看呢?项目文件加下群:1136192749

 

你可能感兴趣的:(Python爬取《创造营2020》小姐姐数据用腾讯云人脸识别做颜值评分)