休假在家期间, 想看生活大爆炸, 于是我上网搜索资源, 找到了天天看美剧这个网站. 该网站资源比较全, 但有一个缺点: 不能打包下载, 只能一集一集下载(如下图所示). 这我可忍受不了, 赶紧写两行代码, 让计算机去做这重复的体力活.
life is short, I use Python. 选用python脚本作为编程工具, 利用requests库获取页面响应, 再用beautifulSoup解析页面即可.
import requests
from bs4 import BeautifulSoup as bs
url = "http://www.ttkmj.net/a/5388"
r = requests.get(url)
soup = bs(r.text,'html.parser')
ret = soup.find('tbody').find_all('a')
magnet = []
for r in ret:
# 磁力链接都是以magnet开头的
if r.get('href') and r.get('href').startswith('magnet'):
magnet.append(r.get('href'))
# 我用的115网盘, 可以批量下载磁力链接,但必须用换行符分隔
print('\n'.join(magnet))
运行结果如下, 直接全选复制到磁力下载器, 即可下完整季24集大爆炸:
magnet:?xt=urn:btih:ef0638a202f64fa07b4b78fa506558a85d9b139d
magnet:?xt=urn:btih:760b7a16eedcd23ff140a70cff311a85d73cb52f
magnet:?xt=urn:btih:202c5b61153df3a810049f0d909beceb959a4e83
magnet:?xt=urn:btih:659d7e3ebfdecd178b60204fd3d7bbec58f313c7
magnet:?xt=urn:btih:3ce2608afdd74d69bc0ed54406be796b27504fba
magnet:?xt=urn:btih:e2f1b87a03eb8bdf608ed7484667e67655cb3203
magnet:?xt=urn:btih:2baaa8e193f65b61c70a689d2d81e4b62bc46b34
magnet:?xt=urn:btih:42d0af38ef987a4b8ef5e90061cf0d998e435088
magnet:?xt=urn:btih:16e421d0263c255e3e057d29b2620b16797be02e
magnet:?xt=urn:btih:1ccda7fee57e0c43b849e1bceed9073355e61a26
magnet:?xt=urn:btih:32f16404015f077730858729614c5ec8c7d8a0d4
magnet:?xt=urn:btih:562b6549cb090ba51a35c5e1fb9ddadb18ab57e6
magnet:?xt=urn:btih:45f622799d39ec5e0e0e7c53ff3358e5e1e66178
magnet:?xt=urn:btih:7a781862df879dbfda8aa7441419b138935a544a
magnet:?xt=urn:btih:a42545012ea26ca41b0fb08a8c2e2c85e5cbd73f
magnet:?xt=urn:btih:28b056680a67739d41c3c76120d661e7ee1ae0e2
magnet:?xt=urn:btih:835c1b91688c144236581ed57133bbc1996262fb
magnet:?xt=urn:btih:edb7083e32dd4547b8eb6a3e3d325f7d40724779
magnet:?xt=urn:btih:ab93741ebd7c5162aedaec542268fc806543301c
magnet:?xt=urn:btih:58e1a08b56a95aaf8381864e4e65f85f58d0195a
magnet:?xt=urn:btih:e4cce61784dfcbb784e0d92d5e3c873b5774a92d
magnet:?xt=urn:btih:b6232539feedc777e021654e6aa1fae91eb887c5
magnet:?xt=urn:btih:103dbd19f2fba971c7d9d914c548ad4a22271486
magnet:?xt=urn:btih:1edd10f148b0585eb1f9d40bcfd13870dc676cfd
网友评论