Hao_Tian22 2019-08-24 23:56 采纳率: 100%
浏览 1300
已采纳

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"}});'

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

  • 写回答

2条回答 默认 最新

  • Hao_Tian22 2019-08-29 10:49
    关注

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

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

    之后一切正常

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 unity3d机械臂
  • ¥20 判断两个表是否完全相同
  • ¥20 工控机出现散热器转一下停一下这种情况,是什么原因造成的
  • ¥15 双显卡,启动docker容器报错。
  • ¥15 想编写一个期货跨期套利的程序
  • ¥15 一个线程在sleep的时候set一个信号会起作用吗
  • ¥50 如何利用matlab将现有的地基雷达回波数据调制为机载雷达回波数据
  • ¥100 需求高精度PT100设计电路和算法
  • ¥15 单片机配网,继电器开关,广播
  • ¥60 Qcustomplot绘制实时动态曲线