当前位置:   article > 正文

python3GUI--微博图片爬取工具V1.5 By:PyQt5(附源码)_微博 相册 爬虫 软件

微博 相册 爬虫 软件


之前写过一款python3GUI–微博图片爬取工具V1.5(附源码)
,是基于python自带的GUI开发包tkinter,实现了对指定用户文章内图片的爬取,本次使用PyQt5,遵循UI界面与爬虫逻辑分离开来,实现思路大体相同,只不过tkinter与QT组件方法有所差别,走起~

一.准备工作

本程序是基于PyQt5的,需要额外安装一下,这里不多说。
UI界面的设计基于QT设计师,用它设计UI很方便。
关于以上模块、工具的安装可以参考PyCharm安装PyQt5及其工具(Qt Designer、PyUIC、PyRcc)详细教程

二.预览

1.启动

怎么样,是不是熟悉的感觉
请添加图片描述

2.搜索

用户搜索会调用两个API进行检索,将搜索到的相关用户去重后,展示在组合框中。
请添加图片描述

3.开始爬取

选取完图片保存路径,点击开始爬取,程序就开始工作了,爬取状态会在表格中实时显示。
请添加图片描述

4.结果

请添加图片描述
仅拿一张图片作为展示。

三.设计流程

1.整体流程

在这里插入图片描述

2.UI设计(草图)

在这里插入图片描述

3.UI设计(QT设计师)

使用QT设计师,设计UI界面,使用QMainWindow作为模板,去除了工具栏与状态栏,保留了菜单栏,使用QLabel、QLineEdit、QPushButton、QCombobox、QTableWidget、QGroupBox等组件。整体垂直布局,局部水平布局。
请添加图片描述

四.源代码

1.Wei_Bo_pics_Crawl.py(主程序)

#-*-coding:utf-8-*-
import os
import sys
from threading import Thread
from PyQt5.Qt import QMainWindow,QMessageBox,QFileDialog,QMenu,QTableWidgetItem,QApplication
from PyQt5.QtCore import pyqtSignal, pyqtSlot, QSize
from PyQt5.QtGui import QPixmap
from Weibo_Crawl_Engine import Weibo_Pic_Spider
from WeiBo_Pics_Crawl import Ui_MainWindow
"""

图片可以爬取了,但是图片爬完的tablewidget显示还有问题    **已解决**
保存图片路径有问题,还要加上用户名子目录名称  **已实现**
1.加载网络图片
2.自定义信号槽,保证tablewidget在UI线程中
"""
class Wei_Bo_Pics_Crawl_Window(QMainWindow):
    single=pyqtSignal(str)
    def __init__(self):
        super().__init__()
        self.s=Weibo_Pic_Spider()
        self.current_path=os.getcwd()
        self.ui=Ui_MainWindow()
        self.ui.setupUi(self)
        self.setFixedSize(self.width(),self.height())
        self.ui.label_show_user_head_img.setMaximumSize(QSize(120,150))
        self.ui.comboBox_users.currentIndexChanged.connect(self.show_user_img)
        self.ui.pushButton_start_crawl.clicked.connect(lambda :self.thread_it(self.do_start_crawl))
        self.ui.action_quit_window.triggered.connect(self.close)
        self.ui.action_do_search.triggered.connect(self.do_search_users)
        self.ui.action_start_crawl.triggered.connect(self.do_start_crawl)
        self.ui.action_do_stop_crawl.triggered.connect(self.do_stop_crawl)
        self.ui.action_open_dir.triggered.connect(self.open_dir)
        self.ui.action_show_about_author.triggered.connect(lambda :QMessageBox.information(self,'关于作者','作者:懷淰メ\nBy:PyQt5'))
        self.ui.tableWidget_show_satauts.customContextMenuRequested.connect(self.show_right_menu)
        self.ui.pushButton_stop_crawl.clicked.connect(self.do_stop_crawl)
        self.single[str].connect(self.insert_into_table_widget)

    def do_search_users(self):
        self.ui.comboBox_users.clear()
        self.s.user_list.clear()
        key_word=self.ui.lineEdit_keyword.text()
        if key_word !='':
            self.search_result=self.s.get_users(key_word)
            if self.search_result:
                user_names=[user_['user_name'] for user_ in self.search_result]
                self.ui.comboBox_users.addItems(user_names)
                self.ui.pushButton_start_crawl.setEnabled(True)
                self.ui.action_start_crawl.setEnabled(True)
            else:
                QMessageBox.information(self,'提示',f'很抱歉,没有检索到关于[{key_word}]的用户!')
        else:
            QMessageBox.warning(self,'警告','关键字不能为空!')

    def do_select_save_path(self):
        while True:
            dir_choose = QFileDialog.getExistingDirectory(self,"选择要视频图片的文件夹",self.current_path)  # 起始路径
            if dir_choose!='':
                self.ui.lineEdit_save_path.setText(dir_choose)
                break

    def do_start_crawl(self):
        save_path = self.ui.lineEdit_save_path.text()
        if save_path == '':
            QMessageBox.warning(self, '警告', '存储路径不能为空!')
        else:
            if os.path.isdir(save_path):
                self.ui.tableWidget_show_satauts.clear()
                self.ui.tableWidget_show_satauts.setRowCount(0)
                self.ui.tableWidget_show_satauts.setHorizontalHeaderLabels(['状态'])
                combobox_current_index = self.ui.comboBox_users.currentIndex()
                user_name = self.search_result[combobox_current_index]['user_name']
                user_id = self.search_result[combobox_current_index]['user_id']
                self.pic_save_dir = save_path + '/' + user_name
                os.makedirs(self.pic_save_dir,exist_ok=True)
                self.s.set_start_url(user_id=user_id)
                self.ui.pushButton_start_crawl.setEnabled(False)
                self.ui.action_start_crawl.setEnabled(False)
                self.ui.pushButton_stop_crawl.setEnabled(True)
                self.ui.action_do_stop_crawl.setEnabled(True)
                self.running_flag=True
                self.do_download_pics()
                if self.ui.action_open_dir_after_crawl.isChecked():
                    os.startfile(self.pic_save_dir)
                self.ui.pushButton_start_crawl.setEnabled(True)
                self.ui.action_start_crawl.setEnabled(True)
                self.ui.action_do_stop_crawl.setEnabled(False)
            else:
                QMessageBox.warning(self, '警告', '所选目录不合法!')
                self.ui.lineEdit_save_path.setText('')

    def do_download_pics(self):
        for pic in self.s.get_pics_url():
            if self.running_flag:
                file_name = pic.split('/')[-1]
                self.s.do_download_pic(pic, file_name, self.pic_save_dir)
                self.single.emit(file_name)
            else:
                self.single.emit('程序已停止!')
                break
        if self.running_flag:
            self.single.emit('图片爬取结束!')

    def show_user_img(self,index):
        current_user_item=self.search_result[index]
        user_header_img_url=current_user_item['user_head_img']
        pix_map=QPixmap()
        header_img_bytes=self.s.get_img_bytes(user_header_img_url)
        pix_map.loadFromData(header_img_bytes)
        self.ui.label_show_user_head_img.setPixmap(pix_map)

    def do_stop_crawl(self):
        self.single.emit('程序正在停止,请耐心等待...')
        self.running_flag=False
        self.ui.pushButton_start_crawl.setEnabled(True)
        self.ui.action_start_crawl.setEnabled(True)
        self.ui.action_do_stop_crawl.setEnabled(False)
        self.ui.pushButton_stop_crawl.setEnabled(False)

    def show_right_menu(self,pos):
        menu=QMenu()
        item=menu.addAction('查看此图片')
        screen_pos=self.ui.tableWidget_show_satauts.mapToGlobal(pos)
        action = menu.exec(screen_pos)
        if action==item:
            try:
                current_pic_name=self.ui.tableWidget_show_satauts.currentItem().text()
                pic_path=self.pic_save_dir+'/'+current_pic_name
                os.startfile(pic_path)
            except AttributeError:
                QMessageBox.warning(self,'警告','请务必选择一张图片!')
            except FileNotFoundError:
                QMessageBox.warning(self,'警告','此为系统消息!')


    def closeEvent(self,event):
        reply = QMessageBox.question(self, '关闭', "确定要退出吗?",
                                     QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)
        if reply == QMessageBox.Yes:
            event.accept()
        else:
            event.ignore()

    @pyqtSlot(str)
    def insert_into_table_widget(self,line):
        row_num=self.ui.tableWidget_show_satauts.rowCount()
        self.ui.tableWidget_show_satauts.setRowCount(row_num+1)
        new_table_widget_item=QTableWidgetItem(line)
        self.ui.tableWidget_show_satauts.setItem(row_num,0,new_table_widget_item)
        self.ui.tableWidget_show_satauts.scrollToBottom()

    def open_dir(self):
        try:
            os.startfile(self.save_path)
        except AttributeError:
            QMessageBox.warning(self,'警告','请先开始爬取图片!')

    def thread_it(self,func,*args):
        t=Thread(target=func,args=args)
        t.setDaemon(True)
        t.start()

if __name__ == '__main__':
    app=QApplication(sys.argv)
    ui=Wei_Bo_Pics_Crawl_Window()
    ui.show()
    sys.exit(app.exec_())
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167

2.WeiBo_Pics_Crawl.py(UI)

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'WeiBo_Pics_Crawl.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.


from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.setEnabled(True)
        MainWindow.resize(496, 466)
        MainWindow.setMouseTracking(False)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.centralwidget)
        self.verticalLayout_2.setObjectName("verticalLayout_2")
        self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_2.setContentsMargins(10, 3, 10, -1)
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setObjectName("label")
        self.horizontalLayout_2.addWidget(self.label)
        self.lineEdit_keyword = QtWidgets.QLineEdit(self.centralwidget)
        self.lineEdit_keyword.setMinimumSize(QtCore.QSize(227, 0))
        self.lineEdit_keyword.setMaximumSize(QtCore.QSize(227, 24))
        self.lineEdit_keyword.setAlignment(QtCore.Qt.AlignCenter)
        self.lineEdit_keyword.setObjectName("lineEdit_keyword")
        self.horizontalLayout_2.addWidget(self.lineEdit_keyword)
        spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_2.addItem(spacerItem)
        self.pushButton_do_search = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_do_search.setObjectName("pushButton_do_search")
        self.horizontalLayout_2.addWidget(self.pushButton_do_search)
        self.verticalLayout_2.addLayout(self.horizontalLayout_2)
        self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_3.setContentsMargins(10, -1, 10, -1)
        self.horizontalLayout_3.setObjectName("horizontalLayout_3")
        self.label_2 = QtWidgets.QLabel(self.centralwidget)
        self.label_2.setObjectName("label_2")
        self.horizontalLayout_3.addWidget(self.label_2)
        self.lineEdit_save_path = QtWidgets.QLineEdit(self.centralwidget)
        self.lineEdit_save_path.setMinimumSize(QtCore.QSize(227, 0))
        self.lineEdit_save_path.setMaximumSize(QtCore.QSize(227, 24))
        self.lineEdit_save_path.setAlignment(QtCore.Qt.AlignCenter)
        self.lineEdit_save_path.setObjectName("lineEdit_save_path")
        self.horizontalLayout_3.addWidget(self.lineEdit_save_path)
        spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_3.addItem(spacerItem1)
        self.pushButton_select_save_path = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_select_save_path.setObjectName("pushButton_select_save_path")
        self.horizontalLayout_3.addWidget(self.pushButton_select_save_path)
        self.verticalLayout_2.addLayout(self.horizontalLayout_3)
        self.horizontalLayout_4 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_4.setContentsMargins(10, -1, 10, -1)
        self.horizontalLayout_4.setObjectName("horizontalLayout_4")
        self.label_3 = QtWidgets.QLabel(self.centralwidget)
        self.label_3.setObjectName("label_3")
        self.horizontalLayout_4.addWidget(self.label_3)
        self.comboBox_users = QtWidgets.QComboBox(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.comboBox_users.sizePolicy().hasHeightForWidth())
        self.comboBox_users.setSizePolicy(sizePolicy)
        self.comboBox_users.setMinimumSize(QtCore.QSize(227, 0))
        self.comboBox_users.setMaximumSize(QtCore.QSize(227, 24))
        self.comboBox_users.setMaxVisibleItems(30)
        self.comboBox_users.setSizeAdjustPolicy(QtWidgets.QComboBox.AdjustToContents)
        self.comboBox_users.setObjectName("comboBox_users")
        self.horizontalLayout_4.addWidget(self.comboBox_users)
        spacerItem2 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_4.addItem(spacerItem2)
        self.pushButton_start_crawl = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_start_crawl.setEnabled(False)
        self.pushButton_start_crawl.setMaximumSize(QtCore.QSize(93, 16777215))
        self.pushButton_start_crawl.setObjectName("pushButton_start_crawl")
        self.horizontalLayout_4.addWidget(self.pushButton_start_crawl)
        self.verticalLayout_2.addLayout(self.horizontalLayout_4)
        self.horizontalLayout_9 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_9.setContentsMargins(-1, -1, 10, -1)
        self.horizontalLayout_9.setObjectName("horizontalLayout_9")
        spacerItem3 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_9.addItem(spacerItem3)
        self.pushButton_stop_crawl = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_stop_crawl.setEnabled(False)
        self.pushButton_stop_crawl.setMaximumSize(QtCore.QSize(93, 16777215))
        self.pushButton_stop_crawl.setObjectName("pushButton_stop_crawl")
        self.horizontalLayout_9.addWidget(self.pushButton_stop_crawl)
        self.verticalLayout_2.addLayout(self.horizontalLayout_9)
        self.horizontalLayout_7 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_7.setSizeConstraint(QtWidgets.QLayout.SetDefaultConstraint)
        self.horizontalLayout_7.setContentsMargins(-1, -1, 10, -1)
        self.horizontalLayout_7.setObjectName("horizontalLayout_7")
        self.horizontalLayout_5 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_5.setContentsMargins(10, -1, 0, -1)
        self.horizontalLayout_5.setObjectName("horizontalLayout_5")
        self.label_4 = QtWidgets.QLabel(self.centralwidget)
        self.label_4.setObjectName("label_4")
        self.horizontalLayout_5.addWidget(self.label_4)
        self.tableWidget_show_satauts = QtWidgets.QTableWidget(self.centralwidget)
        self.tableWidget_show_satauts.setMinimumSize(QtCore.QSize(227, 0))
        font = QtGui.QFont()
        font.setFamily("微软雅黑")
        font.setPointSize(7)
        self.tableWidget_show_satauts.setFont(font)
        self.tableWidget_show_satauts.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.tableWidget_show_satauts.setAlternatingRowColors(True)
        self.tableWidget_show_satauts.setTextElideMode(QtCore.Qt.ElideMiddle)
        self.tableWidget_show_satauts.setVerticalScrollMode(QtWidgets.QAbstractItemView.ScrollPerPixel)
        self.tableWidget_show_satauts.setHorizontalScrollMode(QtWidgets.QAbstractItemView.ScrollPerPixel)
        self.tableWidget_show_satauts.setObjectName("tableWidget_show_satauts")
        self.tableWidget_show_satauts.setColumnCount(1)
        self.tableWidget_show_satauts.setRowCount(0)
        item = QtWidgets.QTableWidgetItem()
        self.tableWidget_show_satauts.setHorizontalHeaderItem(0, item)
        self.tableWidget_show_satauts.horizontalHeader().setStretchLastSection(True)
        self.tableWidget_show_satauts.verticalHeader().setDefaultSectionSize(20)
        self.tableWidget_show_satauts.verticalHeader().setMinimumSectionSize(18)
        self.horizontalLayout_5.addWidget(self.tableWidget_show_satauts)
        spacerItem4 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_5.addItem(spacerItem4)
        self.horizontalLayout_6 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_6.setContentsMargins(0, -1, -1, -1)
        self.horizontalLayout_6.setSpacing(0)
        self.horizontalLayout_6.setObjectName("horizontalLayout_6")
        self.groupBox = QtWidgets.QGroupBox(self.centralwidget)
        self.groupBox.setObjectName("groupBox")
        self.verticalLayout = QtWidgets.QVBoxLayout(self.groupBox)
        self.verticalLayout.setObjectName("verticalLayout")
        self.label_show_user_head_img = QtWidgets.QLabel(self.groupBox)
        self.label_show_user_head_img.setMinimumSize(QtCore.QSize(93, 0))
        self.label_show_user_head_img.setAutoFillBackground(False)
        self.label_show_user_head_img.setStyleSheet("QLabel{\n"
"background-color:rgb(173, 216, 230);\n"
"position:absolute;\n"
"bottom:1;\n"
"}")
        self.label_show_user_head_img.setText("")
        self.label_show_user_head_img.setTextFormat(QtCore.Qt.AutoText)
        self.label_show_user_head_img.setScaledContents(True)
        self.label_show_user_head_img.setAlignment(QtCore.Qt.AlignHCenter|QtCore.Qt.AlignTop)
        self.label_show_user_head_img.setObjectName("label_show_user_head_img")
        self.verticalLayout.addWidget(self.label_show_user_head_img)
        self.horizontalLayout_6.addWidget(self.groupBox)
        self.horizontalLayout_5.addLayout(self.horizontalLayout_6)
        self.horizontalLayout_7.addLayout(self.horizontalLayout_5)
        self.verticalLayout_2.addLayout(self.horizontalLayout_7)
        self.horizontalLayout = QtWidgets.QHBoxLayout()
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.frame = QtWidgets.QFrame(self.centralwidget)
        self.frame.setLayoutDirection(QtCore.Qt.LeftToRight)
        self.frame.setStyleSheet("color: rgb(255, 0, 0);")
        self.frame.setFrameShape(QtWidgets.QFrame.Box)
        self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
        self.frame.setObjectName("frame")
        self.horizontalLayout_8 = QtWidgets.QHBoxLayout(self.frame)
        self.horizontalLayout_8.setContentsMargins(10, -1, 10, -1)
        self.horizontalLayout_8.setObjectName("horizontalLayout_8")
        spacerItem5 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_8.addItem(spacerItem5)
        spacerItem6 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_8.addItem(spacerItem6)
        self.label_6 = QtWidgets.QLabel(self.frame)
        self.label_6.setAlignment(QtCore.Qt.AlignCenter)
        self.label_6.setObjectName("label_6")
        self.horizontalLayout_8.addWidget(self.label_6)
        spacerItem7 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_8.addItem(spacerItem7)
        spacerItem8 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_8.addItem(spacerItem8)
        self.horizontalLayout.addWidget(self.frame)
        self.verticalLayout_2.addLayout(self.horizontalLayout)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 496, 26))
        self.menubar.setObjectName("menubar")
        self.menu = QtWidgets.QMenu(self.menubar)
        self.menu.setObjectName("menu")
        self.menu_2 = QtWidgets.QMenu(self.menubar)
        self.menu_2.setObjectName("menu_2")
        self.menu_3 = QtWidgets.QMenu(self.menubar)
        self.menu_3.setObjectName("menu_3")
        MainWindow.setMenuBar(self.menubar)
        self.action_open_dir = QtWidgets.QAction(MainWindow)
        self.action_open_dir.setObjectName("action_open_dir")
        self.action_quit_window = QtWidgets.QAction(MainWindow)
        self.action_quit_window.setObjectName("action_quit_window")
        self.action_do_search = QtWidgets.QAction(MainWindow)
        self.action_do_search.setObjectName("action_do_search")
        self.action_start_crawl = QtWidgets.QAction(MainWindow)
        self.action_start_crawl.setEnabled(False)
        self.action_start_crawl.setObjectName("action_start_crawl")
        self.action_open_dir_after_crawl = QtWidgets.QAction(MainWindow)
        self.action_open_dir_after_crawl.setCheckable(True)
        self.action_open_dir_after_crawl.setObjectName("action_open_dir_after_crawl")
        self.action_show_about_author = QtWidgets.QAction(MainWindow)
        self.action_show_about_author.setObjectName("action_show_about_author")
        self.action_do_stop_crawl = QtWidgets.QAction(MainWindow)
        self.action_do_stop_crawl.setEnabled(False)
        self.action_do_stop_crawl.setObjectName("action_do_stop_crawl")
        self.menu.addAction(self.action_open_dir)
        self.menu.addSeparator()
        self.menu.addAction(self.action_quit_window)
        self.menu_2.addAction(self.action_do_search)
        self.menu_2.addAction(self.action_start_crawl)
        self.menu_2.addAction(self.action_do_stop_crawl)
        self.menu_2.addSeparator()
        self.menu_2.addAction(self.action_open_dir_after_crawl)
        self.menu_3.addAction(self.action_show_about_author)
        self.menubar.addAction(self.menu.menuAction())
        self.menubar.addAction(self.menu_2.menuAction())
        self.menubar.addAction(self.menu_3.menuAction())

        self.retranslateUi(MainWindow)
        self.pushButton_do_search.clicked.connect(MainWindow.do_search_users)
        self.pushButton_select_save_path.clicked.connect(MainWindow.do_select_save_path)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "微博图片小爬虫-V1.5"))
        self.label.setText(_translate("MainWindow", "关键字:  "))
        self.lineEdit_keyword.setPlaceholderText(_translate("MainWindow", "请输入关键字"))
        self.pushButton_do_search.setText(_translate("MainWindow", "搜索"))
        self.pushButton_do_search.setShortcut(_translate("MainWindow", "Return"))
        self.label_2.setText(_translate("MainWindow", "保存位置:"))
        self.lineEdit_save_path.setPlaceholderText(_translate("MainWindow", "请选择路径"))
        self.pushButton_select_save_path.setText(_translate("MainWindow", "选择"))
        self.pushButton_select_save_path.setShortcut(_translate("MainWindow", "Ctrl+Shift+D"))
        self.label_3.setText(_translate("MainWindow", "用户列表:"))
        self.pushButton_start_crawl.setText(_translate("MainWindow", "开始爬取"))
        self.pushButton_start_crawl.setShortcut(_translate("MainWindow", "Ctrl+Shift+S"))
        self.pushButton_stop_crawl.setText(_translate("MainWindow", "停止爬取"))
        self.label_4.setText(_translate("MainWindow", "当前状态:"))
        item = self.tableWidget_show_satauts.horizontalHeaderItem(0)
        item.setText(_translate("MainWindow", "状态"))
        self.groupBox.setTitle(_translate("MainWindow", "用户头像"))
        self.label_6.setText(_translate("MainWindow", "敬告:本软件仅供学习交流使用"))
        self.menu.setTitle(_translate("MainWindow", "开始"))
        self.menu_2.setTitle(_translate("MainWindow", "操作"))
        self.menu_3.setTitle(_translate("MainWindow", "关于"))
        self.action_open_dir.setText(_translate("MainWindow", "打开文件夹"))
        self.action_open_dir.setShortcut(_translate("MainWindow", "Ctrl+O"))
        self.action_quit_window.setText(_translate("MainWindow", "退出"))
        self.action_quit_window.setShortcut(_translate("MainWindow", "Ctrl+Q"))
        self.action_do_search.setText(_translate("MainWindow", "搜索"))
        self.action_do_search.setShortcut(_translate("MainWindow", "Ctrl+Return"))
        self.action_start_crawl.setText(_translate("MainWindow", "开始爬取"))
        self.action_start_crawl.setShortcut(_translate("MainWindow", "Ctrl+Shift+S"))
        self.action_open_dir_after_crawl.setText(_translate("MainWindow", "爬取完成后打开文件夹"))
        self.action_show_about_author.setText(_translate("MainWindow", "关于作者"))
        self.action_show_about_author.setShortcut(_translate("MainWindow", "Ctrl+B"))
        self.action_do_stop_crawl.setText(_translate("MainWindow", "停止爬取"))
        self.action_do_stop_crawl.setShortcut(_translate("MainWindow", "Ctrl+Shift+B"))

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237
  • 238
  • 239
  • 240
  • 241
  • 242
  • 243
  • 244
  • 245
  • 246
  • 247
  • 248
  • 249
  • 250
  • 251
  • 252
  • 253
  • 254
  • 255
  • 256
  • 257
  • 258
  • 259
  • 260
  • 261
  • 262

3.Weibo_Crawl_Engine.py(爬虫)

由于篇幅,Weibo_Crawl_Engine.py的代码详见:

python3GUI–微博图片爬取工具V1.5(附源码)

五.总结

本次使用PyQt5撰写一款微博图片爬取工具,在爬取过程中遇到了两个难点问题:
1.Qlabel显示网络图片
此问题解决参考了pyqt5加载网路图片,不本地下载。
2.自定义信号槽,保证tablewidget在UI线程中
此问题解决参考了PyQt 5信号与槽的几种高级玩法
感谢各位!程序打包好放在了百度云 密码:8888。思路、代码方面有什么不足欢迎各位大佬指正、批评!

请添加图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/759115
推荐阅读
相关标签
  

闽ICP备14008679号