- 找到对应想要学习的地址,比如:https://www.missevan.com/mdrama/19255
- 进入对应地址后,键盘按F12或者鼠标‘右键-检查’,重新加载页面后,将鼠标分别点Network和Fetch/XHR。点Network是为了获取当前此次页面的加载都有哪些行为,点Fetch/XHR是为了获取当前广播剧对应的所有剧集id(不必登录或者挨个去对应的第几集去下载)
 - 从Network中分析到,Fetch/XHR中的地址:https://www.missevan.com/dramaapi/getdrama?drama_id=19255可以获取到全部剧集id,所以我们从这个地址开始遍历
- 参考代码如下:
import time
import requests
import json
def get_html(url):
response = requests.get(url)
return response
def parse(response):
json_data = response.json()
title = json_data['info']['sound']['soundstr']
soundurl = json_data['info']['sound']['soundurl']
return title, soundurl
def save(title, mp3_data):
path = r'D:\pythonData\MaoEr\ '
with open(path + title + '.mp3', mode='wb') as f:
f.write(mp3_data)
print('当前时间为:', time.time(), '当前剧集《', title, '》下载完成!!!')
start_time = time.time()
print('开始了:', start_time)
url = 'https://www.missevan.com/dramaapi/getdrama?drama_id=19255'
allDramaInfo = get_html(url).text
jsonStr = json.loads(allDramaInfo)
episodes = jsonStr['info']['episodes']['episode']
for episode in episodes:
sound_id = episode['sound_id']
mp3_url = 'https://www.missevan.com/sound/getsound?soundid=' + str(sound_id)
resp_2 = get_html(mp3_url)
title, soundurl = parse(resp_2)
mp3_data = get_html(soundurl).content
save(title, mp3_data)
print('结束了,一共花费了:', time.time() - start_time, '秒')
- 结果如下
 
|