菜鸡源码,专注精品下载!
当前位置:首页 > 建站教程 > 建站知识

使用Python编写一个简单的磁力搜索工具源码

发布时间:2024-01-05  栏目:建站知识   浏览:   分类:python教程 磁力搜索

要开发一个简单版的磁力搜索工具,首先需要安装`requests`和`beautifulsoup4`库。然后,可以使用`requests`库来获取网页内容,使用`beautifulsoup4`库来解析网页内容。接下来,需要编写一个函数来搜索磁力链接。这个函数的输入是一个关键词,输出是包含磁力链接的列表。最后,将这个函数封装成一个类,并提供一个简单的命令行界面来让用户输入关键词并查看搜索结果。

#-*-coding:utf-8-*-"""-------------------------------------------------FileName:main.pyDescription:Author:mycgbdate:2022/10/10-------------------------------------------------"""__author__='mycgb'importrefromPyQt5.QtWidgetsimport*fromPyQt5.QtCoreimport*fromPyQt5.QtGuiimport*importrequests,sys,os,json,timefromlxmlimportetreefromurllibimportparseclasssearch_thread(QThread):"""启动搜索引擎"""startSingout=pyqtSignal(str,list)bools=pyqtSignal(bool)def__init__(self,data,*args,**kwargs):super(search_thread,self).__init__(*args,**kwargs)self.data=dataself.stop=Trueself.headers={"pragma":"no-cache","referer":"https://detail.1688.com/","cookie":'',"upgrade-insecure-requests":"1","user-agent":"Mozilla/5.0(WindowsNT10.0;Win64;x64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/103.0.0.0Safari/537.36"}defrun(self):print('启动线程',self.data)self.url=''data={'1024BT':'https://1024bt106.buzz/main-search-kw-{}-1.html'.format(self.data.get('keyword')),}self.endPage=2#采集页码ifself.data.get('search')=='1024BT':print('1024BT')self.bt1024()self.bools.emit(False)defbt1024(self):#print('启动',self.url)try:foriinrange(1,self.endPage):ifself.stop==False:breakself.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-itemdetail-width"]')#print(href)datas=[]ifhref:foriinhref:ifself.stop==False:breakdts={'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)exceptBaseExceptionase:self.error(e)deferror(self,e):print('请求出错',e)classwindow(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("Searchmoviesandsoftware1.0by:吾爱破解")#设置全局样式#"QWidget{background-image:url('12.jpg');self.setStyleSheet("QLineEdit{color:black;}""QLabel{color:black;}"'QWidget{font-size:22px;font-family:LucidaCalligraphy,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()deftab1UI(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)ifos.path.exists('data')==True:withopen('data','r',encoding='utf-8')asf:fs=f.readlines()foriinfs: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:1pxsolid#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)deflink_clicked(self):print('ssss')self.zanDialog()defhotclicked(self,txt):if'清空记录'==txt:self.keyword.clear()ifos.path.exists('data')==True:os.remove('data')#self.keyword.addItem('清空记录')else:print(txt)defstrat_but(self):print('开始采集',self.keyword.currentText())data={'keyword':self.keyword.currentText(),'search':self.searchList.currentText(),}items=[]foriinrange(self.keyword.count()):item=self.keyword.itemText(i)items.append(item)print(item)ifself.keyword.currentText()notinitems:withopen('data','a',encoding='utf-8')asf:f.write("%sn"%self.keyword.currentText())self.keyword.insertItem(0,self.keyword.currentText())self.keyword.addItem('清除记录')ifself.tab1_but.text()=='搜索[Enter]':ifself.table.rowCount()>0:rowcount=self.table.rowCount()foriinrange(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=Falseself.tab1_but.setText('搜索[Enter]')defstart_info(self,info,data):print('接收数据:',info)ifinfo=='数据':self.status.showMessage('正在搜索数据...')#print('接收数据:',data)foriindata: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)defstrat_bool(self,bool):ifbool==False:print(bool)self.status.showMessage('采集完毕,搜索到数据%s条'%self.table.rowCount())self.tab1_but.setText('搜索[Enter]')#self.tab1_but.setEnabled(True)defgenerateMenu(self,pos):#rint(pos)row_num=-1print('pos',pos)foriinself.table.selectionModel().selection().indexes():row_num=i.row()ifrow_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))ifitem2==action:row_box_list=[]#获取选中数据ifself.table.rowCount()>0:print('选择删除')self.table.removeRow(row_num)elifitem3==action:print('拷贝',row_num)ifrow_num!=-1:item=self.table.item(row_num,4).text()print(item)clipboard=QApplication.clipboard()clipboard.setText(item)elifitem1==action:print('拷贝名称')ifrow_num!=-1:item=self.table.item(row_num,0).text()print(item)clipboard=QApplication.clipboard()clipboard.setText(item)elifaction==item6:print('清空表格')print('表格有',self.table.rowCount())ifself.table.rowCount()>0:rowcount=self.table.rowCount()foriinrange(rowcount):print('当前I的值',i)self.table.removeRow(0)else:returnif__name__=='__main__':importurllib3requests.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_())
相关专题

相关文章

    无相关信息
评论
建站知识
建站知识
使用技巧
调试安装
运营推广