吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 6534|回复: 33
收起左侧

[Python 原创] Python 磁力搜索源码简单版本

  [复制链接]
mycgb 发表于 2022-10-12 17:55
本帖最后由 mycgb 于 2022-10-12 18:09 编辑

[Python] 纯文本查看 复制代码
# -*- 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("%s\n"%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_())


搜索.jpg

打包后的文件下载地址:https://mycgb.lanzouy.com/i9p1z0dm6bdg

免费评分

参与人数 14吾爱币 +15 热心值 +14 收起 理由
searchjack + 1 + 1 我很赞同!
leejwei + 1 + 1 谢谢@Thanks!
wclself + 1 + 1 我很赞同!
menoooooos + 1 + 1 谢谢@Thanks!
ywj + 1 + 1 谢谢@Thanks!
zhaoqingdz + 1 谢谢@Thanks!
syyl + 1 + 1 我很赞同!
冬天冷了多穿点 + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
Pandolar + 3 + 1 我很赞同!
我的睡公主 + 1 + 1 我很赞同!
RUO + 2 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
策士 + 1 鼓励转贴优秀软件安全工具和文档!
luxingyu329 + 1 + 1 支持一下,加油
wkdxz + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!

查看全部评分

本帖被以下淘专辑推荐:

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

 楼主| mycgb 发表于 2022-10-12 18:05
wkdxz 发表于 2022-10-12 18:03
楼主能提供下完整的源码么?想学习下

源码是完整的。只要在search_thread线程里增加自己的采集代码就行。
wkdxz 发表于 2022-10-12 18:08
mycgb 发表于 2022-10-12 18:05
源码是完整的。只要在search_thread线程里增加自己的采集代码就行。

哈哈哈 BT1024 是个三方库吗
wkdxz 发表于 2022-10-12 18:03
 楼主| mycgb 发表于 2022-10-12 18:08
wkdxz 发表于 2022-10-12 18:08
哈哈哈 BT1024 是个三方库吗

直接删掉,那个没用。
luxingyu329 发表于 2022-10-12 18:09
支持楼主,加油
magicny 发表于 2022-10-12 18:24
多谢分享,虽然看不懂。。。。
dokuro 发表于 2022-10-12 18:42
UI是用什么做的?
neteast 发表于 2022-10-12 19:02
用代码,啥也搜索不到。
用下载编译的版本可以搜索到,还带有赞助

差哪了
用温柔将我杀死 发表于 2022-10-12 19:24
好东西收下了
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

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

GMT+8, 2024-11-24 12:33

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

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