利用Python制作百度图片下载器

作者:Python 时间:2021-02-25 09:17:55 

前段时间写了一个百度图片下载器,结果发现有很多人需要使用。说实话之前写的那一款百度图片下载器比较LOW,今天刚好有时间就做了一下升级。

更新了两个BUG,一个是图片下载达到几千张的时候就没有图片可以下载了。另一个是下载进度不能实时的展示出来不知道下载到什么程度了。

利用Python制作百度图片下载器

同样的,我们先把需要的第三方库导入进来。

'''UI界面相关的库'''

from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *

'''应用操作相关的库'''
import sys
import os

from scripy_images import ScripyImages

UI 界面在原来的基础上面增加了文本浏览器可以实时的查看下载进度,还有增加了每一页下载的图片数量的控制让下载数据更加精确。

def init_ui(self):
       self.setWindowTitle('百度图片下载器2.0  公众号:[Python 集中营]')
       self.setWindowIcon(QIcon('下载.ico'))
       self.setFixedSize(550, 300)

grid = QGridLayout()

self.page_label = QLabel()
       self.page_label.setText('设置爬取页数:')
       self.page_line_text = QLineEdit()
       self.page_line_text.setPlaceholderText('输入整数')
       self.page_line_text.setValidator(QIntValidator(1, 99))
       self.page_line_text.setFocus()

self.page_num_label = QLabel()
       self.page_num_label.setText('每页爬取数量:')
       self.page_num_text = QSpinBox()
       self.page_num_text.setRange(50, 100)
       self.page_num_text.setSingleStep(10)
       self.page_num_text.setWrapping(True)

self.keyword_label = QLabel()
       self.keyword_label.setText('设置图关键字:')
       self.keyword_line_text = QLineEdit()
       self.keyword_line_text.setValidator(QRegExpValidator(QRegExp('[\u4E00-\u9FA5]+')))
       self.keyword_line_text.setMaxLength(6)
       self.keyword_line_text.setPlaceholderText('输入汉字')

self.file_path = QLineEdit()
       self.file_path.setPlaceholderText('自定义文件路径')
       self.file_path.setReadOnly(True)
       self.file_path_button = QPushButton()
       self.file_path_button.setText('自定义路径')
       self.file_path_button.clicked.connect(self.file_path_click)

self.request_button = QPushButton()
       self.request_button.setText('快速开始抓取图片')
       self.request_button.clicked.connect(self.download_image)

self.brower = QTextBrowser()
       self.brower.setPlaceholderText('抓取进度结果展示...')

grid.addWidget(self.page_label, 0, 0, 1, 1)
       grid.addWidget(self.page_line_text, 0, 1, 1, 2)
       grid.addWidget(self.page_num_label, 1, 0, 1, 1)
       grid.addWidget(self.page_num_text, 1, 1, 1, 2)
       grid.addWidget(self.keyword_label, 2, 0, 1, 1)
       grid.addWidget(self.keyword_line_text, 2, 1, 1, 2)
       grid.addWidget(self.file_path, 3, 0, 1, 2)
       grid.addWidget(self.file_path_button, 3, 2, 1, 1)
       grid.addWidget(self.brower, 4, 0, 1, 3)
       grid.addWidget(self.request_button, 5, 0, 1, 3)

self.thread_ = ScripyImages(self)
       self.thread_.trigger.connect(self.update_log)
       self.thread_.finished.connect(self.finished)

self.setLayout(grid)

增加控制向文本浏览器中实时写入数据的槽函数。

def update_log(self, text):
       '''
       槽函数:向文本浏览器中写入内容
       :param text:
       :return:
       '''
       cursor = self.brower.textCursor()
       cursor.movePosition(QTextCursor.End)
       self.brower.append(text)
       self.brower.setTextCursor(cursor)
       self.brower.ensureCursorVisible()

优化了图片的下载过程,使用专门的子线程来处理图片下载的部分。

def download_image(self):
       self.request_button.setEnabled(False)
       self.thread_.start()

来源:https://www.cnblogs.com/lwsbc/p/15844351.html

标签:Python,图片,下载
0
投稿

猜你喜欢

  • Python应用实现双指数函数及拟合代码实例

    2023-04-14 18:17:14
  • Python ord函数()案例详解

    2023-06-25 04:50:28
  • 在Python中使用异步Socket编程性能测试

    2023-04-20 23:19:56
  • 形象化的reflow

    2008-06-08 13:33:00
  • Python实现网站注册验证码生成类

    2023-10-24 13:58:02
  • Python flask框架实现浏览器点击自定义跳转页面

    2023-04-26 15:48:31
  • python实现从文件中读取数据并绘制成 x y 轴图形的方法

    2023-04-09 22:43:41
  • 使用Python处理Excel表格的简单方法

    2023-12-07 08:05:04
  • Python实现免费音乐下载器

    2023-12-26 23:51:16
  • Python基于递归算法实现的汉诺塔与Fibonacci数列示例

    2021-07-01 15:57:12
  • Python中docx2txt库的使用说明

    2022-03-23 18:58:46
  • asp如何删除数据库中的表或索引?

    2010-06-26 12:23:00
  • Python Web开发模板引擎优缺点总结

    2023-08-02 22:36:29
  • js断点调试经验分享

    2023-08-15 06:19:09
  • Pandas中df.loc[]与df.iloc[]的用法与异同 

    2023-01-24 07:57:04
  • 亚马逊购物用户体验分析 (二)

    2009-10-25 12:48:00
  • 教你利用Python破解ZIP或RAR文件密码

    2022-04-25 07:11:15
  • Python字符串的15个基本操作(小结)

    2023-08-11 00:11:13
  • js实现登录注册框手机号和验证码校验(前端部分)

    2023-09-13 02:41:37
  • Python基于回溯法子集树模板解决旅行商问题(TSP)实例

    2023-04-27 15:39:32
  • asp之家 网络编程 m.aspxhome.com