1. 程式人生 > 程式設計 >Python 實現自動獲取種子磁力連結方式

Python 實現自動獲取種子磁力連結方式

因為我閒來無事,所以準備找一部電影來看看。 然後我找到了種子搜尋網站,可是這類網站的彈窗廣告太多,搞得我很煩。所以我就想著自己用python寫一個自動獲取磁力連結的指令碼。

整個大概寫了半個小時。

程式碼如下

import requests
import re
from bs4 import BeautifulSoup
 
  
url="*種子的網站*/"
header={
  "Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8","Accept-Encoding":"gzip,deflate","Accept-Language":"zh-CN,zh;q=0.8","Cache-Control":"max-age=0","Connection":"keep-alive","Content-Length":"65","Content-Type":"application/x-www-form-urlencoded","Host":"btkitty.bid","Origin":"*種子的網站*","Referer":"*種子的網站*/","Upgrade-Insecure-Requests":"1","User-Agent":"Mozilla/5.0 (Windows NT 10.0.14393; WOW64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/57.0.2950.5 Safari/537.36"
  }
while True:
  word=input("輸入搜尋關鍵詞:")
  data={
    "keyword":word,"hidden":"true"
    }
  res=requests.post(url,data=data,headers=header)
  bs=BeautifulSoup(res.text,"lxml")
  itemInfo=bs.find_all("dd",class_="option")
  torrent={}
  for item in itemInfo:
    magnet=item.find_next("a",href=re.compile("magnet.*")).attrs["href"]
    name=item.find_previous("a",href=re.compile("*種子的網站*/.*\.html")).text
    size=item.find_next(text=re.compile("\u6587\u4ef6\u5927\u5c0f")).find_next("b").text
    time=item.find_next(text=re.compile("\u6536\u5f55\u65f6\u95f4")).find_next("b").text
    hot=item.find_next(text=re.compile("\u4eba\u6c14")).find_next("b").text
    torrent[name]=[name,time,size,hot,magnet]
 
  for item in torrent:
    print("名稱:",torrent[item][0])
    print("釋出時間:",torrent[item][1])
    print("大小:",torrent[item][2])
    print("熱度:",torrent[item][3])
    print("磁力連結:",torrent[item][4],'\n')  

執行結果如下

以上這篇Python 實現自動獲取種子磁力連結方式就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支援我們。