热门推荐
python linux下载磁力链_菜鸟边学Python边实践之打造自己的磁力搜索神器
2024-11-12 01:22

[Python] 纯文本查看 复制代码import random

python linux下载磁力链_菜鸟边学Python边实践之打造自己的磁力搜索神器

import requests,time

from lxml import etree

import threading

from queue import Queue

urlHome = '网址自行脑补'

myque = Queue()

path = {

//此处可以替换成你自己的XPATH

'HomePage':'//*[@id="list-panel"]/div/h2/a/@href',

'pmagnet':'//*[@id="main-container"]/div/div[1]/div[2]/div[3]/a/@href',

'pname':'//*[@class="title"]/text()',

'pdata':'//*[@class="dtbox"]/ul[4]/li[2]/text()',

'psize':'//*[@class="dtbox"]/ul[3]/li[2]/text()',

}

def run(urlHome,xpath):

a = requests.get(urlHome,timeout = (20,20))

doc = etree.HTML(a.text)

realUrl = doc.xpath(xpath)

for i in realUrl:

myque.put('网址自行脑补' + i)

return myque

def getMagnet(url,pmagnet,psize,pdata,pname):

try:

f = requests.get(url,timeout = (20,20))

if f.status_code == 200:

doc = etree.HTML(f.text)

magnet = doc.xpath(pmagnet)

magnet = magnet[0].split('&')[0]

size = doc.xpath(psize)[0]

data = doc.xpath(pdata)[0]

name = doc.xpath(pname)[0]

print({'片名':name,

'磁力':magnet,

'大小':size,

'种子日期':data})

except:

pass

class Mythread(threading.Thread):

def __init__(self, name):

super().__init__()

self.name = name

def run(self):

while not myque.empty():

url = myque.get()

getMagnet(url,path['pmagnet'],path['psize'],path['pdata'],path['pname'])

time.sleep(random.randint(1, 4))

def main(keyword,maxpage = 5):

for page in range(1,maxpage+1):

urlHome = '网址自行脑补' + keyword + '/p/' + str(page) + '.html'//此处替换成你的网址

run(urlHome,path['HomePage'])

t1 = Mythread('1')

t2 = Mythread('2')

t3 = Mythread('3')

t4 = Mythread('4')

t5 = Mythread('5')

li = [t1,t2,t3,t4,t5]

for each in li:

each.start()

for each in li:

each.join()

if __name__ == '__main__':

    以上就是本篇文章【python linux下载磁力链_菜鸟边学Python边实践之打造自己的磁力搜索神器】的全部内容了,欢迎阅览 ! 文章地址:http://syank.xrbh.cn/quote/7594.html 
     行业      资讯      企业新闻      行情      企业黄页      同类资讯      网站地图      返回首页 迅博思语资讯移动站 http://kaire.xrbh.cn/ , 查看更多