某网站音频下载
原帖 https://www.52pojie.cn/thread-1963688-1-1.html是要下载2楼说的网站里的1800+音频
http://www.yuetingba.cn/book/detail/3a0a4394-004b-58cc-bee6-fd01e7787da4/0
我试着分析了一下
页面是 onclick=testFn('3a0a487b-f73b-aae9-f268-d501098118b9')
只能通过浏览器的开发者工具直接得到真实的mp3地址
1800我多个文件,总不能一个一个下载吧
哪位大神帮分析一下,通过testFn('3a0a487b-f73b-aae9-f268-d501098118b9')如何得到真实的地址
我好写个工具把音频下载下来
抓包 `http://www.yuetingba.cn/api/app/docs-listen/3a0a487b-f73b-aae9-f268-d501098118b9/ting-with-ef` 请求:
```json
{
"id": "3a0a487b-f73b-aae9-f268-d501098118b9",
"bookId": "3a0a4394-004b-58cc-bee6-fd01e7787da4",
"tingNo": 1,
"title": "",
"ef": "Ob1B4vtdV6FAXBD3sD3PlI02ie5zefztNrbsg7VpNwRxvQfcxrTgKcUDnTF/weOy8Ut7cNwUVGLgfsY6RQuAfegb3ogVjwIwzwG5Qxaplve/S5JTVFlupQ99g2eRi8E2D5SBAhY3EIbFxVyvIEHH2Q=="
}
```
剩下的就很简单了,交给你自己琢磨:
```js
let wo = new class {
constructor() {
this.key = mo.enc.Base64.parse("le95G3hnFDJsBE+1/v9eYw=="),
this.iv = mo.enc.Base64.parse("IvswQFEUdKYf+d1wKpYLTg==")
}
encrypt(e) {
const t = mo.enc.Utf8.parse(e);
return mo.AES.encrypt(t, this.key, {
iv: this.iv,
mode: mo.mode.CBC,
padding: mo.pad.Pkcs7
}).ciphertext.toString(mo.enc.Base64)
}
decrypt(e) {
e = (e + "").replace(/\n*$/g, "").replace(/\n/g, "");
const t = mo.enc.Base64.parse(e)
, n = mo.enc.Base64.stringify(t);
return mo.AES.decrypt(n, this.key, {
iv: this.iv,
mode: mo.mode.CBC,
padding: mo.pad.Pkcs7
}).toString(mo.enc.Utf8).toString()
}
}
```
![](https://imgsrc.baidu.com/forum/pic/item/2e2eb9389b504fc2a9474627a3dde71190ef6dfc.png)
import requests
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad, unpad
import base64
from bs4 import BeautifulSoup
from concurrent.futures import ThreadPoolExecutor
import os
import time
from tqdm import tqdm
# 定义加密解密类
class Crypter:
def __init__(self):
self.key = base64.b64decode('le95G3hnFDJsBE+1/v9eYw==')
self.iv = base64.b64decode('IvswQFEUdKYf+d1wKpYLTg==')
def encrypt(self, data):
data = data.encode('utf-8')
cipher = AES.new(self.key, AES.MODE_CBC, self.iv)
ciphertext = cipher.encrypt(pad(data, AES.block_size))
return base64.b64encode(ciphertext).decode('utf-8')
def decrypt(self, ciphertext):
ciphertext = base64.b64decode(ciphertext)
cipher = AES.new(self.key, AES.MODE_CBC, self.iv)
data = unpad(cipher.decrypt(ciphertext), AES.block_size)
return data.decode('utf-8')
# 获取mp3链接
def get_mp3_url(url):
response = requests.get(url, headers=headers)
soup = BeautifulSoup(response.text, 'html.parser')
mp3_url_list = []
for a in soup.find_all('a', title=True, onclick=True):
title = a['title']
if title:
id = a['onclick'].split("'")
url = f'http://www.yuetingba.cn/api/app/docs-listen/{id}/ting-with-ef'
mp3_url = 'http://117.65.51.119:50010' + Crypter().decrypt(requests.get(url, headers=headers).json()['ef'])
mp3_url_list.append((title, mp3_url))
return mp3_url_list
# 下载mp3文件
def download_mp3(mp3_url_list):
with ThreadPoolExecutor(max_workers=None) as executor:
futures = []
for title, mp3_url in mp3_url_list:
# print(title,mp3_url)
filename = f'资治通鉴(白话文)/{title}.mp3'
if os.path.exists(filename):
print(f'{title}.mp3 已存在')
continue
future = executor.submit(download_file, mp3_url, filename)
futures.append(future)
# 使用tqdm显示进度条
for future in tqdm(futures):
try:
future.result()
except Exception as e:
print(f'下载失败: {e}')
# 下载文件的辅助函数
def download_file(url, filename):
response = requests.get(url, headers=headers)
with open(filename, 'wb') as f:
f.write(response.content)
print(f'{filename} 下载完成')
# 主程序
if __name__ == '__main__':
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:130.0) Gecko/20100101 Firefox/130.0',
}
base_url = 'http://www.yuetingba.cn/book/detail/3a0a4394-004b-58cc-bee6-fd01e7787da4/0'
response = requests.get(base_url, headers=headers)
soup = BeautifulSoup(response.text, 'html.parser')
nav_tabs = soup.find('ul', class_='nav nav-tabs').find_all('a')
#使用多线程下载
with ThreadPoolExecutor() as executor:
for a in nav_tabs:
url = 'http://www.yuetingba.cn' + a['href']
# print(url)
mp3_url_list = get_mp3_url(url)
executor.submit(download_mp3, mp3_url_list)
多线程下载的也很慢 http://117.65.51.119:50010/myfiles/host/listen/%E5%90%AC%E4%B9%A6%E7%9B%AE%E5%BD%95/%E8%B5%84%E6%B2%BB%E9%80%9A%E9%89%B4(%E7%99%BD%E8%AF%9D%E6%96%87)~%E5%8F%B8%E9%A9%AC%E5%85%89~%E5%B3%BB%E5%AE%87/c36ca68eab2245fc9c42c7519d4612b0.mp3,用猫抓能嗅探到,但是一个个的点和编号有点痛苦。 netsome 发表于 2024-9-14 09:12
http://117.65.51.119:50010/myfiles/host/listen/%E5%90%AC%E4%B9%A6%E7%9B%AE%E5%BD%95/%E8%B5%84%E6%B2% ...
是啊,通过浏览器自带的开发者工具也能得到这个IP
一个一个的下载,太麻烦 爱飞的猫 发表于 2024-9-14 04:08
抓包 `http://www.yuetingba.cn/api/app/docs-listen/3a0a487b-f73b-aae9-f268-d501098118b9/ting-wi ...
版主出手就是厉害 静待楼主写好工具 本帖最后由 msmvc 于 2024-9-14 10:52 编辑
爱飞的猫 发表于 2024-9-14 04:08
抓包 `http://www.yuetingba.cn/api/app/docs-listen/3a0a487b-f73b-aae9-f268-d501098118b9/ting-wi ...
感谢版主
ef=Ob1B4vtdV6FAXBD3sD3PlI02ie5zefztNrbsg7VpNwRxvQfcxrTgKcUDnTF/weOy8Ut7cNwUVGLgfsY6RQuAfQGnaVEteiPSdZoyBC8E8B5kIPLJnXSxzZZu1LnfRVtcgykcXcuN5J8ZgCwCv1OyQQ==
de=/myfiles/host/listen/听书目录/资治通鉴(白话文)~司马光~峻宇/de3306fd640f42d4ad3feb25b0a36dd2.mp3
就差 如何取得这个ef的值了
anorith 发表于 2024-9-14 10:03
静待楼主写好工具
等我啊,晚上回家后写一下 本帖最后由 llyaomo 于 2024-9-14 10:23 编辑
利用猫爪嗅探的话,还要外挂下载器,期待楼主搞个一步到位 llyaomo 发表于 2024-9-14 10:22
利用猫爪嗅探的话,还要外挂下载器,期待楼主搞个一步到位
必须整一个,等我
页:
[1]
2