本帖最后由 Summer1003 于 2022-10-13 12:14 编辑
可以半次元网站Cos板块的单个网站,(全站爬虫可能会封IP)
开源代码如下:
UI部分:
[Python] 纯文本查看 复制代码
# -*- coding: utf-8 -*-# Form implementation generated from reading ui file 'ui.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, QtWidgetsclass Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(554, 273) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap("logo.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) MainWindow.setWindowIcon(icon) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.lineEdit = QtWidgets.QLineEdit(self.centralwidget) self.lineEdit.setGeometry(QtCore.QRect(130, 20, 231, 31)) self.lineEdit.setObjectName("lineEdit") self.IDLable = QtWidgets.QLabel(self.centralwidget) self.IDLable.setGeometry(QtCore.QRect(60, 30, 54, 12)) self.IDLable.setTextFormat(QtCore.Qt.AutoText) self.IDLable.setObjectName("IDLable") self.IsClicked = QtWidgets.QPushButton(self.centralwidget) self.IsClicked.setGeometry(QtCore.QRect(370, 20, 91, 31)) self.IsClicked.setAutoRepeatInterval(100) self.IsClicked.setObjectName("IsClicked") self.progressBar = QtWidgets.QProgressBar(self.centralwidget) self.progressBar.setGeometry(QtCore.QRect(130, 60, 261, 31)) self.progressBar.setProperty("value", 0) self.progressBar.setObjectName("progressBar") self.textBrowser = QtWidgets.QTextBrowser(self.centralwidget) self.textBrowser.setGeometry(QtCore.QRect(50, 100, 391, 141)) self.textBrowser.setObjectName("textBrowser") MainWindow.setCentralWidget(self.centralwidget) self.statusbar = QtWidgets.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "半次元器")) self.IDLable.setText(_translate("MainWindow", "请输入ID")) self.IsClicked.setText(_translate("MainWindow", "确定"))
主函数部分:
[Python] 纯文本查看 复制代码
# -*- coding: utf-8 -*-# Form implementation generated from reading ui file 'connect_me.ui'## Created by: PyQt5 UI code generator 5.11.3## WARNING! All changes made in this file will be lost!#导入程序运行必须模块import sys#PyQt5中使用的基本控件都在PyQt5.QtWidgets模块中from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox#导入designer工具生成的login模块from ui import Ui_MainWindowimport requests, json, re, osclass MyMainForm(QMainWindow, Ui_MainWindow): ID = 0 def __init__(self, parent=None): super(MyMainForm, self).__init__(parent) self.setupUi(self) self.setFixedSize(self.width(), self.height()) if self.progressBar.value() == 0: self.progressBar.hide() self.IsClicked.clicked.connect(self.Download) def Download(self): self.ID = self.lineEdit.text() url = 'https://bcy.net/item/detail/%s' % self.ID headers = { 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36 Edg/89.0.774.68' } res = requests.get(url, headers=headers) html = res.text dir_name = url.split('/')[-1] if os.path.exists(dir_name) is False: os.mkdir(dir_name) json_str = re.findall(r'window.__ssr_data = https://www.52pojie.cn/JSON.parse(.*)', html)[0][1:-2] res_json = json.loads(json_str) extension = re.findall(r'"format":"(.*?)"', res_json) uncoding_url = re.findall(r'"origin":"(.*?)"', res_json) encoding = [] for i in uncoding_url: encoding.append(i.encode().decode("unicode-escape")) num = 0 self.progressBar.setMaximum(len(encoding)) self.progressBar.show() for target in encoding: QApplication.processEvents() file_name = re.findall('https://p3-bcy-sign.bcyimg.com/banciyuan/(.*?)~', target)[0] if os.path.exists(file_name) is False: target_res = requests.get(target, headers=headers) file = target_res.content with open(dir_name + '/' + file_name + '.' + extension[num], 'wb') as f: f.write(file) num += 1 self.progressBar.setValue(num) pwd = os.getcwd() self.textBrowser.setText("文件保存于:" + pwd + '\\' + dir_name)if __name__ == "__main__": #固定的,PyQt5程序都需要QApplication对象。sys.argv是命令行参数列表,确保程序可以双击运行 app = QApplication(sys.argv) #初始化 myWin = MyMainForm() #将窗口控件显示在屏幕上 myWin.show() #程序运行,sys.exit方法确保程序完整退出。 sys.exit(app.exec_())
可执行文件:
:https://wwd.lanzoub.com/i3uvI0dqmu6d 密码:fnma