長按點贊,等你來幹!!!
這裡的主要步驟其實還是和我們之前分析的一樣,如下圖所示:
這裡再簡單帶大家看一下就行,重點是我們的第二部分。
既然網頁結構我們已經分析完了,那麼我還是選擇用之前的xpath來爬取我們所需要的資源。
# 獲取所有的主播資訊
defgetdatas
(html)
: datalist=
parse=parsel.selector(html)
lis=parse.xpath(
'//li[@class="game-live-item"]'
).getall(
)# print(lis)
for li in lis:
data =
parse1=parsel.selector(li)
img_src=parse1.xpath(
'//img[@class="pic"]/@data-original'
).get(
"data"
) title=parse1.xpath(
'//i[@class="nick"]/@title'
).get(
"data"
) redu=parse1.xpath(
'//i[@class="js-num"]/text()'
).get(
"data"
)return datalist
#儲存主播頭像
defdownload
(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爬蟲/虎牙顏值主播排名"
這樣我們顏值檢測的介面流程基本就已經理清楚了,**如下:
def
face_rg
(file_path)
: api_key =
'你的 api key'
secret_key =
'你的 secret key'
with
open
(file_path,
'rb')as
file
: data=base64.b64encode(
file
.read())
image=data.decode(
) imagetype =
"base64"
""" 如果有可選引數 """
options =
options[
"face_field"]=
"beauty"
""" 帶引數呼叫人臉檢測 """
result=client.detect(image, imagetype, options)
# print(result)
return result[
'result'][
'face_list'][
0]['beauty'
]
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)
)
Python爬蟲 看看虎牙女主播中誰最「頂」!
這裡再簡單帶大家看一下就行,重點是我們的第二部分。既然網頁結構我們已經分析完了,那麼我還是選擇用之前的xpath來爬取我們所需要的資源。獲取所有的主播資訊 def getdatas html datalist parse parsel.selector html lis parse.xpath li...
python爬蟲看看虎牙女主播中誰最「頂」步驟詳解
網頁鏈結 https ww程式設計客棧w.huya.com g 4079 這裡的主要步驟其實還是和我們之前分析的一樣,如下圖所示 這裡再簡單帶大家看一下就行,重點是我們的第二部分。既然網頁結構我們已經分析完了,那麼我還是選擇用之前的xpath來爬取我們所需要的資源。獲取所有的主播資訊 def get...
python3爬蟲虎牙星秀
準備工具 python3.5.x 和 pycharm 安裝 beautifulsoup4 這個包 import requests from bs4 import beautifulsoup import re from urllib import request import time url 要爬...