利用Python开发个简单版的磁力搜索工具源码

随心笔谈2年前发布 编辑
167 0
🌐 经济型:买域名、轻量云服务器、用途:游戏 网站等 《腾讯云》特点:特价机便宜 适合初学者用 点我优惠购买
🚀 拓展型:买域名、轻量云服务器、用途:游戏 网站等 《阿里云》特点:中档服务器便宜 域名备案事多 点我优惠购买
🛡️ 稳定型:买域名、轻量云服务器、用途:游戏 网站等 《西部数码》 特点:比上两家略贵但是稳定性超好事也少 点我优惠购买

# -*- coding: utf-8 -*-
“””
————————————————-
File Name: main.py
Description :
Author : mycgb
date: 2022/10/10
————————————————-
“””
__author__ = ‘mycgb’

import re

from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
import requests,sys,os,json,time
from lxml import etree
from urllib import parse

class search_thread(QThread):
“””启动搜索引擎”””
startSingout = pyqtSignal(str,list)
bools = pyqtSignal(bool)
def __init__(self, data, *args, **kwargs):
super(search_thread, self).__init__(*args, **kwargs)
self.data = data
self.stop = True
self.headers = {
“pragma”: “no-cache”,
“referer”: “https://detail.1688.com/”,
“cookie”: ”,
“upgrade-insecure-requests”: “1”,
“user-agent”: “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36″
}
def run(self):
print(‘启动线程’, self.data)
self.url = ”
data = {
‘1024BT’: ‘https://1024bt106.buzz/main-search-kw-{}-1.html’.format(self.data.get(‘keyword’)),
}
self.endPage = 2 # 采集页码
if self.data.get(‘search’) == ‘1024BT’:
print(‘1024BT’)
self.bt1024()
self.bools.emit(False)
def bt1024(self):
# print(‘启动’, self.url)
try:
for i in range(1,self.endPage):
if self.stop == False:
break
self.url = ‘https://1024bt106.buzz/main-search-kw-{}-{}.html’.format(self.data.get(‘keyword’),i)
html = requests.get(self.url, headers=self.headers,timeout=15)
# print(html.text)
href = etree.HTML(html.text).xpath(‘//div[@class=”col-md-8″]/div[@class=”search-item detail-width”]’)
# print(href)
datas = []
if href:
for i in href:
if self.stop == False:
break
dts = {
‘title’: “”.join(i.xpath(‘./div[@class=”item-title”]/h3/a/@title’)),
‘datetime’: “”.join(i.xpath(‘./div[@class=”item-bar”]//span[2]/b/text()’)),
‘size’: “”.join(i.xpath(‘./div[@class=”item-bar”]//span[3]/b/text()’)),
‘hot’: “”.join(i.xpath(‘./div[@class=”item-bar”]//span[4]/b/text()’)),
‘downlink’: “”.join(i.xpath(‘./div[@class=”item-bar”]//span[5]/a/@href’)),
}
# print(dts)
datas.append(dts)
self.startSingout.emit(‘数据’, datas)
except BaseException as e:
self.error(e)
def error(self,e):
print(‘请求出错’,e)
class window(QWidget):
def __init__(self,parent=None):
super(window, self).__init__(parent)
self.setGeometry(500, 300, 1380, 820)
# self.setWindowTitle(“西西趣天日本广告管理助手1.0”)
# 软件居中显示***********
qr = self.frameGeometry()
cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
self.setWindowTitle(“Search movies and software 1.0 by:吾爱破解”)
#设置全局样式
#”QWidget{background-image: url(’12.jpg’);
self.setStyleSheet(“QLineEdit{color:black;}”
“QLabel{color:black;}”
‘QWidget{font-size:22px;font-family:Lucida Calligraphy,cursive, serif, sans-serif;}’
“QComboBox{color:black;padding-left:2px;height:30px;width:100px;}”
“QComboBox:drop-down{width:20px;}”
“QTableWidget{font-size:18px;background-color:#F2F2F2;}”
# “QComboBox:down-arrow{border: none;}”
# “QComboBox:item{color:black;}”
# “QComboBox::hover{color:white;}”
“QPushButton{color:black,height:30px;}”
# “QTextEdit{background-color:black;color:white}”
)
self.setMinimumWidth(600)
self.setMinimumHeight(320)
self.ver = ‘1.0’
self.tab1UI()
def tab1UI(self):
self.tab1_but = QPushButton(self)
self.tab1_but.setText(‘搜索[Enter]’)
self.tab1_but.clicked.connect(self.strat_but)
self.tab1_but.setShortcut(Qt.Key_Enter)
self.keyword = QComboBox(self)
self.keyword.setEditable(True)
# self.keyword.addItems([‘蜘蛛侠’,’功夫熊猫’,’清空记录’])
# self.keyword.setFocusPolicy(Qt.ClickFocus)
self.keyword.currentTextChanged.connect(self.hotclicked)
if os.path.exists(‘data’) == True:
with open(‘data’,’r’,encoding=’utf-8′) as f:
fs = f.readlines()
for i in fs:
self.keyword.addItem(i.strip())
# self.tab1_but2 = QPushButton(self)
# self.tab1_but2.setText(‘导出数据’)
# self.tab1_but2.clicked.connect(self.savecsv)
self.keyword.addItem(‘清空记录’)
self.searchList = QComboBox(self)
self.searchList.addItems([
‘搜索全部’,
“1024BT”,
“2048BT”,
’52BT’,
‘Magnet’,
’91bt’,
‘btmovi’,
‘BTSOW’,
‘thepiratebay’,
‘bt天堂’,’kuba’,’软件搜索’,’nyaa’,’rutor’,’torrentproject2′
])
self.searchList.setStyleSheet(“QComboBox{width:200px;text-align: center;}”)
# self.zan_label.setOpenExternalLinks(True)
self.bottom_date = QLabel(self)
self.bottom_date.setText(time.strftime(‘%Y-%m-%d %H:%M’))

self.table = QTableWidget(self)
self.table.setStyleSheet(“QTableWidget{background-color:white;color:black;selection-background-color:#6666CC;}”
“QHeaderView::section,QTableCornerButton:section{
padding:3px; margin:0px; color:#DCDCDC; border:1px solid #242424;
border-left-width:0px; border-right-width:1px; border-top-width:0px; border-bottom-width:1px;
background:qlineargradient(spread:pad,x1:0,y1:0,x2:0,y2:1,stop:0 #6666CC,stop:1 #6666CC); }”
)
self.table.setSortingEnabled(True)#自动排序
self.table.setColumnCount(5)
self.table.setShowGrid(True)
self.table.resizeRowsToContents()#内容自动宽度
self.table.horizontalHeader().setStretchLastSection(True)
self.table.setContextMenuPolicy(Qt.CustomContextMenu) ######允许右键产生子菜单
self.table.customContextMenuRequested.connect(self.generateMenu) ####右键菜单
self.table.verticalHeader().setHidden(True) # 隐藏左边行号
self.table.setSelectionBehavior(QAbstractItemView.SelectRows)
self.table.horizontalHeader().setSectionsClickable(True)
CateHeader = [
‘标题’,
‘大小’,
‘更新时间’,
‘点击量’,
‘磁力链接’,
]
self.table.setHorizontalHeaderLabels(CateHeader)
self.adList = QLabel(self)
self.adList.setMaximumWidth(700)
self.adList.setOpenExternalLinks(True)
self.status = QStatusBar(self)
self.status.showMessage(‘准备就绪’)
self.status.addPermanentWidget(self.adList)

# self.status.addPermanentWidget(QLabel(‘联系作者:Q:252577315’))
self.status2 = QStatusBar(self)
self.status2.showMessage(‘所有数据均来源于网络,勿违反国家法律法规!仅供作为技术交流与提升等用途!’)
self.status2.addPermanentWidget(self.bottom_date)
# self.status.addPermanentWidget(self.tab1_count)
self.vbox = QVBoxLayout(self)
self.hbox = QHBoxLayout(self)
self.hbox2 = QHBoxLayout(self)
self.hbox.addWidget(QLabel(‘输入关键词:’))
self.hbox.addWidget(self.keyword,30)
self.hbox.addWidget(self.searchList)
self.hbox.addWidget(self.tab1_but)
# self.hbox.addWidget(self.tab1_but2)
self.vbox.addLayout(self.hbox)
self.vbox.addWidget(self.status2)
self.vbox.addWidget(self.table)
self.vbox.addWidget(self.status)
self.setLayout(self.vbox)
def link_clicked(self):
print(‘ssss’)
self.zanDialog()
def hotclicked(self,txt):
if ‘清空记录’ == txt:
self.keyword.clear()
if os.path.exists(‘data’) == True:
os.remove(‘data’)
# self.keyword.addItem(‘清空记录’)
else:
print(txt)
def strat_but(self):
print(‘开始采集’,self.keyword.currentText())
data = {
‘keyword’:self.keyword.currentText(),
‘search’:self.searchList.currentText(),
}
items = []
for i in range(self.keyword.count()):
item = self.keyword.itemText(i)
items.append(item)
print(item)
if self.keyword.currentText() not in items:
with open(‘data’,’a’,encoding=’utf-8′) as f:
f.write(“%sn”%self.keyword.currentText())
self.keyword.insertItem(0,self.keyword.currentText())
self.keyword.addItem(‘清除记录’)

if self.tab1_but.text() == ‘搜索[Enter]’:
if self.table.rowCount() > 0:
rowcount = self.table.rowCount()
for i in range(rowcount):
print(‘当前I的值’, i)
self.table.removeRow(0)
self.tab1_but.setText(‘停止搜索’)
# self.tab1_but.setEnabled(False)
self.status.showMessage(‘正在搜索数据…’)
self.start_thread = search_thread(data) # 实例化线程对象上传数据
self.start_thread.startSingout.connect(self.start_info)
self.start_thread.bools.connect(self.strat_bool)
self.start_thread.start()
else:
print(‘停止搜索’)
self.start_thread.stop = False
self.tab1_but.setText(‘搜索[Enter]’)
def start_info(self,info,data):
print(‘接收数据:’,info)
if info ==’数据’:
self.status.showMessage(‘正在搜索数据…’)
# print(‘接收数据:’,data)
for i in data:
row = self.table.rowCount()
self.table.insertRow(row)
self.table.setItem(row,0,QTableWidgetItem(‘%s’%i.get(“title”)))
self.table.setItem(row,1, QTableWidgetItem(‘%s’ % i.get(“size”)))
self.table.setItem(row,2, QTableWidgetItem(‘%s’ % i.get(“datetime”)))
self.table.setItem(row,3, QTableWidgetItem(‘%s’ % i.get(“hot”)))
self.table.setItem(row,4, QTableWidgetItem(‘%s’ % i.get(“downlink”)))
else:
self.status.showMessage(info)
def strat_bool(self,bool):
if bool == False:
print(bool)
self.status.showMessage(‘采集完毕,搜索到数据%s条’%self.table.rowCount())
self.tab1_but.setText(‘搜索[Enter]’)
# self.tab1_but.setEnabled(True)
def generateMenu(self, pos):
# rint( pos)
row_num = -1
print(‘pos’,pos)
for i in self.table.selectionModel().selection().indexes():
row_num = i.row()
if row_num < self.table.rowCount():
menu = QMenu()
item1 = menu.addAction(QIcon(r”:copy.png”), u’复制名称’)
item2 = menu.addAction(QIcon(r”:del.png”),u’选择删除’)
item3 = menu.addAction(QIcon(r”:copy.png”),u’复制链接’)
item6 = menu.addAction(QIcon(r”:clear.png”),u”清空数据”)
# item8 = menu.addAction(u”关于软件”)
action = menu.exec_(self.table.mapToGlobal(pos))

if item2 == action:
row_box_list = []
# 获取选中数据
if self.table.rowCount() > 0:
print(‘选择删除’)
self.table.removeRow(row_num)
elif item3 == action:
print(‘拷贝’,row_num)
if row_num != -1:
item = self.table.item(row_num,4).text()
print(item)
clipboard = QApplication.clipboard()
clipboard.setText(item)
elif item1 == action:
print(‘拷贝名称’)
if row_num != -1:
item = self.table.item(row_num,0).text()
print(item)
clipboard = QApplication.clipboard()
clipboard.setText(item)
elif action == item6:
print(‘清空表格’)
print(‘表格有’, self.table.rowCount())
if self.table.rowCount()>0:
rowcount = self.table.rowCount()
for i in range(rowcount):
print(‘当前I的值’, i)
self.table.removeRow(0)
else:
return
if __name__ == ‘__main__’:
import urllib3
requests.packages.urllib3.disable_warnings()
urllib3.disable_warnings()
app = QApplication(sys.argv)
app.setWindowIcon(QIcon(r”:ic.png”))
tw = window()
QApplication.setStyle(QStyleFactory.create(‘Fusion’))
tw.show()
sys.exit(app.exec_())

© 版权声明

相关文章