首页 编程教程正文

宅男福利图片播放工具

piaodoo 编程教程 2020-02-22 22:12:28 1208 0 python教程

本文来源吾爱破解论坛

本帖最后由 洛枫 于 2019-7-1 16:44 编辑

我觉得是宅男的福利,哈哈哈、
双线程边下边播图片

exe在这:
链接:https://pan.baidu.com/s/143Aj7AohwHakktHKUf99jw
提取码:4idj

[Python] 纯文本查看 复制代码

# coding:utf-8
from requests import get
from bs4 import BeautifulSoup
import os
import cv2
from threading import Thread
from time import sleep


scroll_index = 0
pic_index = 0

def show_img(path):
    img = cv2.imread(path)
    height, width = img.shape[:2]
    size = (int(width*0.6), int(height*0.6))
    shrink = cv2.resize(img, size, interpolation=cv2.INTER_AREA)
    cv2.imshow('image', shrink)
    cv2.waitKey(1000)

def scroll_show():  # pic_total
    global scroll_index, pic_index
    while 1:
        if scroll_index < pic_index:
            print("播放图[%d]" % scroll_index)
            show_img(str(scroll_index) + r'.jpg')
            scroll_index += 1
        else:
            sleep(1)

def download_img():
    global scroll_index, pic_index
    url = r'https://www.mzitu.com/zipai/'
    headers = {
        'Referer': 'https://www.mzitu.com/zipai/',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.157 Safari/537.36',
    }
    html = get(url, headers=headers)
    soup = BeautifulSoup(html.text, 'lxml')
    pages = int(soup.find(class_='page-numbers current').string)
    page_index = pages
    pic_index = 0
    for t in range(pages):
        url_new = r'https://www.mzitu.com/zipai/comment-page-%d/#comments' % page_index
        page_index -= 1
        print("访问地址:", url_new)
        html = get(url_new, headers=headers)
        soup = BeautifulSoup(html.text, 'lxml')
        items = soup.find_all('img', class_='lazy')
        items_len = len(items)
        print("本页[%d]张" % items_len)
        for i in range(items_len):
            pic_response = get(items[i]['data-original'], headers=headers)
            with open(str(pic_index)+r'.jpg', 'wb') as f:
                f.write(pic_response.content)
            print("图[%d]下载完成" % pic_index)
            pic_index += 1
        print('*' * 50)
    return pic_index

def main():
    global scroll_index, pic_index
    try:
        print("创建目录")
        os.mkdir(os.getcwd() + r'\pic')
    except:
        print("目录存在")
    os.chdir(os.getcwd() + r'\pic')
    print("文件路径:", os.getcwd())

    scroll_index = 0
    download_thread = Thread(target=download_img)
    scroll_thread = Thread(target=scroll_show)
    download_thread.start()
    scroll_thread.start()
    download_thread.join()
    scroll_thread.join()

    cv2.destroyAllWindows()
    os._exit(0)


if __name__ == '__main__':
    main()

版权声明:

本站所有资源均为站长或网友整理自互联网或站长购买自互联网,站长无法分辨资源版权出自何处,所以不承担任何版权以及其他问题带来的法律责任,如有侵权或者其他问题请联系站长删除!站长QQ754403226 谢谢。

有关影视版权:本站只供百度云网盘资源,版权均属于影片公司所有,请在下载后24小时删除,切勿用于商业用途。本站所有资源信息均从互联网搜索而来,本站不对显示的内容承担责任,如您认为本站页面信息侵犯了您的权益,请附上版权证明邮件告知【754403226@qq.com】,在收到邮件后72小时内删除。本文链接:https://www.piaodoo.com/7798.html

搜索