鱼C论坛

 找回密码
 立即注册
查看: 164|回复: 1

程序报错,大神帮救救

[复制链接]
发表于 2024-10-11 10:58:31 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
复制的论坛大神的,跑不出来
import requests

import re

import json

import os







def get_name(singer):

    url = 'https://c.y.qq.com/soso/fcgi-bin/client_search_cp'

    params = {

    'catZhida': '1',

    'w': singer,

    }

    headers = {

    'referer': 'https://y.qq.com/portal/search.html',

    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36'

    }

    html = requests.get(url,headers=headers,params=params).text

    content = re.compile('callback\((.*)\)').findall(html)[0]

    content = json.loads(content)

    data = content.get('data')

    song = data.get('song')

    lists = song.get('list')

    name = []

    for list in lists:

        singer = list.get('singer')[0].get('mid')

        name.append(singer)

    name = name[0]

    return name



def get_html(name,singer):

    url = 'https://c.y.qq.com/v8/fcg-bin/fcg_v8_singer_track_cp.fcg'

    params = {

    'singermid': name,

    'order': 'listen',

    'begin': '0',

    'num': '30',

    }

    headers = {

    'referer': 'https://y.qq.com/n/yqq/singer/003aQYLo2x8izP.html',

    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36'

    }

    html = requests.get(url,headers=headers,params=params).text

    return html





def get_music(vkey,songname,filename,singer):

    if vkey and songname:

        url3 = 'http://dl.stream.qqmusic.qq.com/' + filename + '?vkey=' + vkey + '&guid=7133372870&uin=0&fromtag=66'



        headers = {

        'referer': 'https://y.qq.com/n/yqq/singer/003aQYLo2x8izP.html',

        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36'

        }

        music = requests.get(url3,headers=headers).content

        dir = singer

        if not os.path.exists(dir):

            os.mkdir(dir)

        with open(dir+'/'+songname+'.m4a','wb') as f:

            f.write(music)

        print(songname,'__',singer)



def get_vkey(strMediaMid,songmid,songname,singer):

    if strMediaMid and songmid and songname :

        url2 = 'https://c.y.qq.com/base/fcgi-bin/fcg_music_express_mobile3.fcg'

        params = {

        'g_tk': '5381',

        'jsonpCallback': 'MusicJsonCallback8571665793949388',

        'loginUin': '0',

        'hostUin': '0',

        'format': 'json',

        'inCharset': 'utf8',

        'outCharset': 'utf-8',

        'notice': '0',

        'platform': 'yqq',

        'needNewCode': '0',

        'cid': '205361747',

        'callback': 'MusicJsonCallback8571665793949388',

        'uin': '0',

        'songmid': songmid,

        'filename': 'C400'+ strMediaMid + '.m4a',

        'guid': '7133372870'

        }

        headers = {

        'referer': 'https://y.qq.com/portal/player.html',

        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36'

        }

        detail_html = requests.get(url2,headers=headers,params=params).text

        vkey_disc = re.compile('MusicJsonCallback8571665793949388\((.*?)\)').findall(detail_html)[0]

        vkey_disc = json.loads(vkey_disc)



        data = vkey_disc['data']

        items = data.get('items')[0]

        vkey = items.get('vkey')

        get_music(vkey,songname,'C400'+ strMediaMid + '.m4a',singer)





def get_list(detail_html,singer):

    if detail_html:

        lists = re.compile('data":{"list":(.*?),"singer_id',re.S).findall(detail_html)[0]

        datas = json.loads(lists)

        for data in datas:

            musicData = data.get('musicData')

            strMediaMid = musicData.get('strMediaMid')

            songmid = musicData.get('songmid')

            songname = musicData.get('songname')

            get_vkey(strMediaMid,songmid,songname,singer)







def main():

    singer = input('请输入您想要下载的歌手:')

    name = get_name(singer)

    detail_html = get_html(name,singer)

    get_list(detail_html,singer)



if __name__ == '__main__':

    main()
报错如下
D:\PYTHON_NEW\pack20240926\pythonProject1\.venv\Scripts\python.exe D:\PYTHON_NEW\pack20240926\pythonProject1\tkinter练习\爬虫测试\测试qq音乐爬虫.py
D:\PYTHON_NEW\pack20240926\pythonProject1\tkinter练习\爬虫测试\测试qq音乐爬虫.py:37: SyntaxWarning: invalid escape sequence '\('
  content = re.compile('callback\((.*)\)').findall(html)[zxsq-anti-bbcode-0]
D:\PYTHON_NEW\pack20240926\pythonProject1\tkinter练习\爬虫测试\测试qq音乐爬虫.py:177: SyntaxWarning: invalid escape sequence '\('
  vkey_disc = re.compile('MusicJsonCallback8571665793949388\((.*?)\)').findall(detail_html)[zxsq-anti-bbcode-0]
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

头像被屏蔽
发表于 2024-11-14 09:22:11 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-12-22 01:09

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表