json 网络爬虫问题,李荣浩的歌出不来

在学爬虫的时候一直收到这样的error:
File “/Users/chrizhuu/.pyenv/versions/3.7.3/lib/python3.7/json/decoder.py”, line 355, in raw_decode
raise JSONDecodeError(“Expecting value”, s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

想请问有没有人能帮我修改一下代码,我找不出原因。第一段代码是爬了李荣浩的,第二段代码爬周杰伦的时候同样的代码就可以

第一段:

``
import requests
url = 'https://c.y.qq.com/soso/fcgi-bin/client_search_cp'
i= 1
for i in range (5):
    params = {
    'ct': '24',
    'qqmusic_ver': '1298',
    'new_json': '1',
    'remoteplace': 'sizer.yqq.song_next',
    'searchid': '37236357190407105',
    't': '0',
    'aggr': '1',
    'cr': '1',
    'catZhida': '1',
    'lossless': '0',
    'flag_qc': '0',
    'p': str(i+1),
    'n': '10',
    'w': '李荣浩',
    'g_tk': '5381',
    'loginUin': '0',
    'hostUin': '0',
    'format': 'json',
    'inCharset': 'utf8',
    'outCharset': 'utf-8',
    'notice': '0',
    'platform': 'yqq.json',
    'needNewCode': '0'
    }
    res_music = requests.get(url, params = params)
    json_music = res_music.json()
    song_list = json_music['data']['song']['list']

    for music in song_list:
        title = music['name']
        url = 'https://y.qq.com/n/yqq/song/'+music['mid']+'.html'
        release = music['time_public']
        duration = str(round(float(music['interval'])/60,2))
        print('歌曲名称: %s' % title)
        print('发布日期: %s' % release)
        print('所属专辑:'+ music['album']['name'])
        print('歌曲时长: %s 分钟' % duration)
        print('播放链接: %s' % url, '\n')


**第二段**
import requests

url = 'https://c.y.qq.com/soso/fcgi-bin/client_search_cp'
for x in range(5):
    params = {
    'ct':'24',
    'qqmusic_ver': '1298',
    'new_json':'1',
    'remoteplace':'sizer.yqq.song_next',
    'searchid':'64405487069162918',
    't':'0',
    'aggr':'1',
    'cr':'1',
    'catZhida':'1',
    'lossless':'0',
    'flag_qc':'0',
    'p':str(x+1),
    'n':'20',
    'w':'周杰伦',
    'g_tk':'5381',
    'loginUin':'0',
    'hostUin':'0',
    'format':'json',
    'inCharset':'utf8',
    'outCharset':'utf-8',
    'notice':'0',
    'platform':'yqq.json',
    'needNewCode':'0'
    }
    # 将参数封装为字典
    res_music = requests.get(url,params=params)
    # 调用get方法,下载这个字典
    json_music = res_music.json()
    # 使用json()方法,将response对象,转为列表/字典
    list_music = json_music['data']['song']['list']
    # 一层一层地取字典,获取歌单列表
    for music in list_music:
    # list_music是一个列表,music是它里面的元素
        print(music['name'])
        # 以name为键,查找歌曲名
        print('所属专辑:'+music['album']['name'])
        # 查找专辑名
        print('播放时长:'+str(music['interval'])+'秒')
        # 查找播放时长
        print('播放链接:https://y.qq.com/n/yqq/song/'+music['mid']+'.html\n\n')
        # 查找播放链接

    x = 1
    for x in range(5):
        res_comments = requests.get(
            'https://c.y.qq.com/base/fcgi-bin/fcg_global_comment_h5.fcg?g_tk=5381&loginUin=0&hostUin=0&format=json&inCharset=utf8&outCharset=GB2312¬ice=0&platform=yqq.json&needNewCode=0&cid=205360772&reqtype=2&biztype=1&topid=246492240&cmd=8&needmusiccrit=0&pagenum=' + str(
                x) + '&pagesize=25&lasthotcommentid=song_246492240_2241651841_1582805272&domain=qq.com&ct=24&cv=10101010')
        # 调用get方法,下载评论列表
        x += 1
        json_comments = res_comments.json()
        # 使用json()方法,将response对象,转为列表/字典
        list_comments = json_comments['comment']['commentlist']
        # 一层一层地取字典,获取评论列表
        for comment in list_comments:
            # list_comments是一个列表,comment是它里面的元素
            print(comment['rootcommentcontent'])
            # 输出评论
            print('-----------------------------------')
            # 将不同的评论分隔开来


你可能感兴趣的:(python,json,大数据)