Python爬取喜马拉雅有声小说【转载】

话不多说 直接上源码

爬取喜马拉雅有声小说—夜惊魂

import re
import os
import json
import requests

def Night_fright():
start_url=‘https://www.ximalaya.com/revision/play/album?albumId=2683677&pageNum={}&sort=0&pageSize=30
headers={
“User-Agent”: “Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36”
}

for n in range(10):
    url = start_url.format(n + 1)
    r=requests.get(url,headers=headers)
    ret=r.content.decode()
    result=json.loads(ret)
    list=result['data']['tracksAudioPlay']
    for i in list:
        src=i['src']
        name=i['trackName']
        name=re.sub('\?|"|\|','',name)
        with open('./mp4/{}.m4a'.format(name),'ab') as f:
            mus=requests.get(src,headers=headers)
            f.write(mus.content)
            print(name)

if name==‘main’:
Night_fright()

猜你喜欢

转载自blog.csdn.net/u010194453/article/details/92066572
今日推荐