weixin_44477794
Hao_Tian22
2019-08-24 23:56
采纳率: 50%
浏览 1.1k

python爬取酷狗音乐返回值不正常

程序中链接返回值与浏览器返回值不一样
链接如下
https://wwwapi.kugou.com/yy/index.php?r=play/getdata&callback=jQuery191044011229047114075_1566198263706&hash=2398DDFC7C7420AB22A77DFEAE4CA551&album_id=1966068&dfid=1afQI30nxtgd0PXOun1bVc82&mid=2ccec311dd30b13705a140e6b7710e64&platid=4&_=1566198263708

浏览器中返回
jQuery191044011229047114075_1566198263706({"status":1,"err_code":0,"data":{"hash":"2398DDFC7C7420AB22A77DFEAE4CA551","timelength":215000,"filesize":8608960,"audio_name":"\u5468\u6770\u4f26 - \u544a\u767d\u6c14\u7403","have_album":1,"album_name":"\u5468\u6770\u4f26\u7684\u5e8a\u8fb9\u6545\u4e8b","album_id":"1645030","img":"http:\/\/imge.kugou.com\/stdmusic\/20160623\/20160623233610830051.jpg","have_mv":1,"video_id":"589001","author_name":"\u5468\u6770\u4f26","song_name":"","lyrics":"","author_id":"3520","privilege":0,"privilege2":"0","play_url":"","authors":[{"author_id":"3520","sizable_avatar":"http:\/\/singerimg.kugou.com\/uploadpic\/softhead\/{size}\/20180515\/20180515002522714.jpg","is_publish":"1","author_name":"\u5468\u6770\u4f26","avatar":"http:\/\/singerimg.kugou.com\/uploadpic\/softhead\/400\/20180515\/20180515002522714.jpg"}],"bitrate":320,"audio_id":"22084042"}});

requests.get(url)

程序返回结果为
'jQuery191044011229047114075_1566198263706({"status":0,"err_code":30020,"data":{"SSA-CODE":"gz_event_78fdc6448481401404133bcd88b001b1","SSA-HMID":"2ccec311dd30b13705a140e6b7710e64"}});'

怎么办?请大神解决
初步判断是网络原因,不网络不一样

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • weixin_44477794
    Hao_Tian22 2019-08-29 10:49
    已采纳

    找到了,在某些网络下,获取此json需要传cookies参数,而某些网络却不用(酷狗这操作好沙雕)
    代码改为

    requests.get(url=url, headers=headers ,cookies=cookies).text
    

    之后一切正常

    点赞 评论
  • Enderman_xiaohei
    小黑LLB 2019-08-25 16:16

    我也觉得是网络问题,我这边直接运行也没问题。
    图片说明

    点赞 评论
  • cjl525574193
    传说中的程序员~ 2020-11-24 20:20

    cookies怎么拿到的

    点赞 评论

相关推荐