吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 3792|回复: 24
收起左侧

[Python 转载] 爬取表情包软件带gui界面 附成品

  [复制链接]
cdsgg 发表于 2020-12-6 15:46
本帖最后由 cdsgg 于 2020-12-6 16:33 编辑

[Python] 纯文本查看 复制代码
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'expressionWeb.ui'
#
# Created by: PyQt5 UI code generator 5.15.1
#
# 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.
import sys
from datetime import datetime
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import QThread, pyqtSignal
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QApplication, QMainWindow, QFileDialog, QMessageBox
import os
import requests
from bs4 import BeautifulSoup
import re




class Ui_Form(object):
        def setupUi(self, Form):
                Form.setObjectName("Form")
                Form.resize(371, 329)
                self.progressBar = QtWidgets.QProgressBar(Form)
                self.progressBar.setGeometry(QtCore.QRect(117, 91, 151, 23))
                self.progressBar.setProperty("value", 0)
                self.progressBar.setObjectName("progressBar")
                self.accordingToSituation = QtWidgets.QTextBrowser(Form)
                self.accordingToSituation.setGeometry(QtCore.QRect(0, 182, 371, 148))
                self.accordingToSituation.setObjectName("accordingToSituation")
                # self.accordingToSituation.setLineWrapMode(1)
                self.progressOf = QtWidgets.QLabel(Form)
                self.progressOf.setGeometry(QtCore.QRect(70, 91, 72, 23))
                self.progressOf.setObjectName("progressOf")
                self.layoutWidget = QtWidgets.QWidget(Form)
                self.layoutWidget.setGeometry(QtCore.QRect(33, 49, 311, 25))
                self.layoutWidget.setObjectName("layoutWidget")
                self.horizontalLayout = QtWidgets.QHBoxLayout(self.layoutWidget)
                self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
                self.horizontalLayout.setObjectName("horizontalLayout")
                self.label = QtWidgets.QLabel(self.layoutWidget)
                self.label.setObjectName("label")
                self.horizontalLayout.addWidget(self.label)
                self.numberPages = QtWidgets.QLineEdit(self.layoutWidget)
                self.numberPages.setObjectName("numberPages")
                self.horizontalLayout.addWidget(self.numberPages)
                self.grab = QtWidgets.QPushButton(self.layoutWidget)
                self.grab.setObjectName("grab")
                self.horizontalLayout.addWidget(self.grab)
                self.pushButton = QtWidgets.QPushButton(Form)
                self.pushButton.setGeometry(QtCore.QRect(110, 140, 121, 23))
                self.pushButton.setObjectName("pushButton")
                # self.pushButton.clicked.connect(self.slot_btn_chooseDir)
                self.grab.clicked.connect(self.just)

                self.retranslateUi(Form)
                QtCore.QMetaObject.connectSlotsByName(Form)

        def retranslateUi(self, Form):
                _translate = QtCore.QCoreApplication.translate
                Form.setWindowTitle(_translate("Form", "表情包软件"))
                self.progressOf.setText(_translate("Form", "进度"))
                self.label.setText(_translate("Form", "  输入页数:"))
                self.grab.setText(_translate("Form", "抓取"))
                self.pushButton.setText(_translate("Form", "功能待定"))

        def settxt(self,wd):
                self.accordingToSituation.setText(wd)

        def GrabExpression(self, data):
                self.progressBar.setValue(data)
                # self.updatas()
                # self.accordingToSituation.setText(data)
                if data == 100:
                        # QMessageBox.information(w, '提示', '保存成功')
                        # self.progressBar.setValue(0)
                        # self.accordingToSituation.setText('保存成功')
                        # self.grab.setText('保存成功')
                        QMessageBox.information(w,'提示','保存成功')
                        self.numberPages.setText('')
                        self.progressBar.setValue(0)
                        self.grab.setText('抓取')
                else:
                        pass


        def just(self):
                # global bs
                # bs=self.slot_btn_chooseDir()
                self.update_data_thread = UpdateData()
                self.update_data_thread.update_date.connect(self.GrabExpression)
                self.update_data_thread.upda_name.connect(self.stext)

                self.update_data_thread.start()


        def toObtainInputBox(self):
                urls=self.numberPages.text()
                return urls

        def erross(self):
                self.grab.setText('失败')
        # def updatas(self):
        #         self.update_data_thread = UpdateData()
        #         self.update_data_thread.upda_name.connect(self.GrabExpression)
        #         self.update_data_thread.start()
        def stext(self,datas):
                self.accordingToSituation.insertPlainText(datas)



class UpdateData(QThread,Ui_Form):
        """更新数据类"""
        update_date = pyqtSignal(int)
        upda_name=pyqtSignal(str) # pyqt5 支持python3的str,没有Qstring

        def run(self):
                t=1
                a = 0
                page=int(UI.toObtainInputBox())
                curr_time = datetime.datetime.now()#获取系统时间

                fw=100/page
                path = datetime.datetime.strftime(curr_time, '%Y%m%d%H%M')
                        # print(path)
                if os.path.exists(path):#检查是否存在这个文件夹
                        # print("属于这个时间点的文件夹已经创建好")
                        pass
                else:
                        os.mkdir(path)#不存在则创建
                        print("创建成功!!!!正在保存图片")
                dirname = os.getcwd() + '\\' + path + '\\'
                print(dirname)
                while t<=page:
                        # ase=UI.slot_btn_chooseDir()
                        try:# test=self.xuanquwenjian()
                                url=f'https://fabiaoqing.com/biaoqing/lists/page/{t}.html'#获取连接
                                # print(curr_time)#打印时间 测试用
                                headers = {
                                        'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1'}# 'cookie': 'tvfe_boss_uuid=4427f26b6d83d5d7; pgv_pvid=8192465356; pgv_pvi=2750494720; RK=cfw14pvSFY; ptcz=026939cd8bdd917551be81f3d0d2563bdb9e2d0805f4c83de8df0ea6af457e49; eas_sid=i1e690x1l8v2I68559J4e8K995; LW_sid=W1C6S0u1y8a2A6E864o8L480Z0; LW_uid=51H6V041L8i2n6Q8M4S8e4k0D0; uin_cookie=o0878530130; ied_qq=o0878530130; o_cookie=878530130; pac_uid=1_878530130; luin=o0878530130; lskey=000100000f95a236a0b3f6a309a1f6e4809612024104f9a476a9b0803995ce53ec225971d5d95f3164c7df7a; rewardsn=; wxtokenkey=777'}

                                
                                req = requests.get(url=url, headers=headers).content.decode()
                        except Exception as e:
                                # QMessageBox.information(w,'提示','报错!!!')
                                UI.erross()
                                return

                        soup = BeautifulSoup(req, 'lxml')#用BeautifulSoup解析网页

                        res = soup.select('img[class="ui image lazy"]')
                        # cd=len(res)
                        # fw=100/cd#获取该网页中所有的图片标签

                        
                        for i in res:#遍历所有的图片标签
                                if i.get("data-original") == None:#如果这个标签内的data-original等于空的时候直接跳过
                                        pass
                                else:
                                        try:#尝试去保存图片 如果保存图片错误则抛出异常
                                                # UI.stext(ase)
                                                with open(dirname + f'{i.get("alt")}'+os.path.splitext(i.get("data-original"))[-1], 'wb') as f:#拼接路径+a.jpg a是等于数字 每添加一个 a自增一 相当于是给图片命名 并且以二进制的形式写入 
                                                        f.write(requests.get(url=i.get("data-original"), headers=headers).content)#向这个图片发送请求 并将图片的二进制写入
                                                        f.close()
                                                        #关闭写入
                                                        self.upda_name.emit(f'已保存第{a}张图片\n')  # 发射信号


                                                        a = a + 1#a自增一
                                        except Exception as e:#抛出异常 增加程序强壮性
                                                print("出现异常了")
                        # self.upda_name.emit(f'=============================================================\n')  # 发射信号

                        print("保存成功")
                        t=t+1  # 发射信号
                        self.update_date.emit((fw*t)-1)

                self.update_date.emit(100)

if __name__ == "__main__":
        app = QApplication(sys.argv)
        w = QMainWindow()
        UI = Ui_Form()
        UI.setupUi(w)
        w.setWindowIcon(QIcon("ts.ico"))
        w.show()
        app.exec_()

完成品:

https://wwa.lanzouj.com/ip4Fjj3sa9e

1.png
1.gif

免费评分

参与人数 3吾爱币 +2 热心值 +3 收起 理由
银狐狸 + 1 我很赞同!
大大大白菜7 + 1 + 1 我很赞同!
乱花渐欲迷人眼 + 1 + 1 用心讨论,共获提升!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

jidesheng6 发表于 2020-12-6 18:35
乱花渐欲迷人眼 发表于 2020-12-6 16:42
快40M了 为啥会这么大阿

python打包的程序,首先自带了一个python解释器,然后依赖包如果使用import xxx,而不是from xxx import xxx,加上还有一个qt5的库,40M算是很小的了
乱花渐欲迷人眼 发表于 2020-12-7 08:26
jidesheng6 发表于 2020-12-6 18:35
python打包的程序,首先自带了一个python解释器,然后依赖包如果使用import xxx,而不是from xxx import  ...

多谢大神答疑
sam喵喵 发表于 2020-12-6 15:50
 楼主| cdsgg 发表于 2020-12-6 15:53
sam喵喵 发表于 2020-12-6 15:50
支持,楼主厉害,上面是全部源码吗

是的 就这些

免费评分

参与人数 1吾爱币 +1 收起 理由
sam喵喵 + 1 谢谢@Thanks!

查看全部评分

楠囝 发表于 2020-12-6 15:59
支持,楼主厉害,上面是全部源码吗
kzx5208 发表于 2020-12-6 16:17
支持,楼主厉害
ff5500 发表于 2020-12-6 16:19
我需要各种各样的滑稽的表情~~~~~~~~~~
wanshiz 发表于 2020-12-6 16:22
有实力啊,羡慕了。
 楼主| cdsgg 发表于 2020-12-6 16:22
ff5500 发表于 2020-12-6 16:19
我需要各种各样的滑稽的表情~~~~~~~~~~

你可以多爬几页  可能有
乱花渐欲迷人眼 发表于 2020-12-6 16:42
快40M了 为啥会这么大阿
 楼主| cdsgg 发表于 2020-12-6 16:45
乱花渐欲迷人眼 发表于 2020-12-6 16:42
快40M了 为啥会这么大阿

不晓得 python写程序 日常这么大 各种依赖包
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-25 15:42

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表