91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 6KB
    文件類型: .py
    金幣: 2
    下載: 1 次
    發(fā)布日期: 2021-05-15
  • 語(yǔ)言: Python
  • 標(biāo)簽: python??

資源簡(jiǎn)介

此源碼直接可以運(yùn)行在自己的軟件里面,爬取付費(fèi)的4K高清圖片,可移植,有詳細(xì)的講解和注釋,適合爬蟲小白進(jìn)行進(jìn)階學(xué)習(xí)。

資源截圖

代碼片段和文件信息

#?-*-?coding?:??utf-8?-*-
#?@Time??????:??2020/8/8
#?@author????:??王小王
#?@Software??:??PyCharm
#?@CSDN??????:??https://blog.csdn.net/weixin_47723732

import?requests
from?PIL?import?Image
from?lxml?import?etree
from?multiprocessing.pool?import?Pool??#?多線程
import?os
import?time


#?在使用PIL
#?image處理圖像要獲取高質(zhì)量的關(guān)鍵地方是下面兩點(diǎn):
#?處理時(shí)要用
#?ANTIALIAS;
#?保存時(shí)是要設(shè)置
#?quality;
#
#?在python
#?ide
#?可以這樣處理:
#
#?im.resize(box?Image.ANTIALIAS)??#?抗據(jù)此
#?im.save(path?‘JPEG‘?quality=95)??#?圖片質(zhì)量大小


def?get_groups(url?headers):??#?獲得重要信息
????“““根據(jù)傳入的最初網(wǎng)址,獲得每個(gè)專欄的網(wǎng)址和標(biāo)題“““
????r?=?requests.get(url?headers=headers)
????r.encoding?=?r.apparent_encoding??#?轉(zhuǎn)換編碼
????if?r.status_code?==?200:??#?如果請(qǐng)求成功,就執(zhí)行下面的操作
????????html?=?etree.HTML(r.text)
????????html?=?etree.tostring(html)
????????html?=?etree.fromstring(html)
????????url_list?=?html.xpath(r“//div[@class=‘classify?clearfix‘]//a/@href“)??#?獲得網(wǎng)頁(yè)分組的url
????????name?=?html.xpath(r“//div[@class=‘classify?clearfix‘]//a/text()“)??#?獲得網(wǎng)頁(yè)分組的標(biāo)題

????else:
????????print(‘請(qǐng)求錯(cuò)誤!‘)
????return?name?url_list??#?把分組標(biāo)題和分組網(wǎng)址回溯


def?begin_down(title?url?headers):??#?下載選擇
????print(‘滲透VIP方式下載高清4K圖片‘.center(30?‘-‘))
????for?i?j?in?enumerate(title):
????????print(i?‘\t\t\t\t\t‘?j)
????inp?=?int(input(‘輸入下載選項(xiàng):‘))
????#?print(title[inp]?url[inp])
????#?get_image_1st(title[inp]?url[inp]?headers)??#?調(diào)用第一頁(yè)的網(wǎng)址進(jìn)行下載
????get_image(title[inp]?url[inp]?headers)??#?下載剩下的所有頁(yè)


def?image_down(title?page_url?headers):??#?下載圖片
????if?not?os.path.exists(title?+?‘//‘):
????????os.mkdir(title?+?‘//‘)
????????os.chdir(title?+?‘//‘)
????else:
????????os.chdir(title?+?‘//‘)
????for?i?j?in?enumerate(page_url):??#?遍歷第一頁(yè)的圖表列表
????????r?=?requests.get(j?headers=headers)??#?請(qǐng)求這個(gè)圖片網(wǎng)址
????????if?r.status_code?==?200:
????????????r.encoding?=?r.apparent_encoding??#?修改編碼
????????????html?=?etree.HTML(r.text)
????????????html?=?etree.tostring(html)
????????????html?=?etree.fromstring(html)??#?以上搭建xpath對(duì)象
????????????url?=?html.xpath(r‘//a[@id=“img“]/img/@src‘)
????????????name?=?html.xpath(r‘//a[@id=“img“]/img/@title‘)
????????????rr?=?requests.get(‘http://pic.netbian.com‘?+?‘‘.join(url)?headers=headers)
????????????if?rr.status_code?==?200:??#?請(qǐng)求下載圖片網(wǎng)址
????????????????rr.encoding?=?rr.apparent_encoding??#?修改編碼
????????????????#??判斷有無(wú)
????????????????if?os.path.exists(‘‘.join(name)?+?‘.png‘):
????????????????????continue
????????????????else:
????????????????????with?open(‘‘.join(name)?+?‘.png‘?‘wb‘)?as?fw:
????????????????????????fw.write(rr.content)
????????????????????img?=?Image.open(‘‘.join(name)?+?‘.png‘)
????????????????????

評(píng)論

共有 條評(píng)論