不活跃种子删种脚本

Posted by

删种小助手。

  1. import requests
  2. from urllib.parse import urljoin
  3. from lxml import etree
  4. import time
  5. import re
  6.  
  7. headers = {
  8.     'cookie': '_ga=GA1.2.286413587.1547475887; c_secure_ssl=eWVhaA%3D%3D; __cfduid=dddfa4fdd9060f1d5a337e3d5c87994231571281870; c_secure_uid=NTAxMDU%3D; c_secure_pass=97fc05ad9da6b047fd227bcd6bd68262; c_secure_tracker_ssl=eWVhaA%3D%3D; c_secure_login=bm9wZQ%3D%3D; _gid=GA1.2.37242126.1580051094',
  9.     'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36'
  10. }
  11.  
  12. s = requests.session()
  13.  
  14. # 构建列表
  15. print("构建列表...")
  16. cat_li, index = [], 7
  17. while index <= 33:
  18.     cat_li.append("https://www.tjupt.org/torrents.php?inclbookmarked=0&incldead=0&picktype=0&spstate=0&cat=409&page=%d" % index)
  19.     index += 1
  20. print("构建完成...")
  21. # 获取请求
  22. print("请求种子列表...")
  23. to_li = []
  24. for cat_item in cat_li:
  25.     print(cat_item)
  26.     content = s.get(cat_item, headers=headers).text
  27.     html = etree.HTML(content)
  28.     html_data = html.xpath("//table[@class='torrentname']//a/@href")
  29.     for im in html_data:
  30.         i = str(im)
  31.         if i.startswith("detail"):
  32.             to_li.append(urljoin("https://www.tjupt.org", i))
  33.     # time.sleep(2)
  34. print("种子列表获取成功...")
  35. # 获取种子详情
  36. print("获取种子详情...")
  37. i, length = 1, len(to_li)
  38. for url in to_li:
  39.     print("Task %d/%d: " % (i, length)+ url)
  40.     id = re.findall(r'id=(\d*)&', url)[0]
  41.     content = s.get(url, headers=headers).text
  42.     html = etree.HTML(content)
  43.     html_data = html.xpath("//b[text()='最近活动种子:']/../text()")
  44.     # 删除种子
  45.     if str(html_data[0]).startswith("2020-01-"):
  46.         data = {
  47.             'id': id,
  48.             'reasontype': '1',
  49.             'reason[]': ''
  50.         }
  51.         s.post('https://www.tjupt.org/delete.php', headers=headers, data=data)
  52.         print("Torrent:%s delete done!" % id)
  53.         # time.sleep(2)
  54.     else:
  55.         print("Torrent:%s last active at %s" % (id, str(html_data[0])))
  56.         # time.sleep(2)
  57.     i += 1

Leave a Reply

电子邮件地址不会被公开。 必填项已用*标注