第九周作業(yè):顏值打分

import requests
from lxml import etree
import time

headers = {
    'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'
}

path = 'http://www.itdecent.cn'

def get_url(url):
    res = requests.get(url,headers=headers)
    html = etree.HTML(res.text)
    infos = html.xpath('//ul[@class="note-list"]/li')
    for info in infos:
        href = info.xpath('div/a/@href')[0]
        det_url = path + href
        print(det_url)
        get_img(det_url)
    time.sleep(2)

def get_img(url):
    i = 1
    res = requests.get(url, headers=headers)
    html = etree.HTML(res.text)
    title = html.xpath('/html/body/div[1]/div[2]/div[1]/h1/text()')[0].strip('|').split(',')[0].split('/')[0]
    id = html.xpath('/html/body/div[1]/div[2]/div[1]/div[1]/div/span/a/text()')[0]
    # print(title,id)
    infos = html.xpath('//div[@class="image-package"]')
    for info in infos:
        img_url = 'http:' + info.xpath('div[1]/div[2]/img/@data-original-src')[0]
        print(img_url)
        res_1 = requests.get(img_url,headers=headers)
        fp = open('row_img/' + title + '+' + id + '+' + str(i) + '.jpg','wb')
        fp.write(res_1.content)
        i = i + 1


if __name__ == '__main__':
    urls = ['http://www.itdecent.cn/c/bd38bd199ec6?order_by=added_at&page={}'.format(str(i)) for i in range(1,10)]
    for url in urls:
        get_url(url)

結(jié)果:


爬取圖片
人臉識別
結(jié)果
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容