Skip to content

Instantly share code, notes, and snippets.

Created February 17, 2016 04:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/550d8d595215ef0267dd to your computer and use it in GitHub Desktop.
Save anonymous/550d8d595215ef0267dd to your computer and use it in GitHub Desktop.
获取网易云音乐歌曲评论
<?php
// 获取网易云音乐歌曲评论
function curl_get($url){
$host = parse_url($url);
$site = $host['scheme']."://".$host['host'];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_REFERER, $site);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)');
curl_setopt($ch, CURLOPT_HTTPHEADER , array('X-FORWARDED-FOR:1.2.4.8', 'X-FORWARDED-HOST:'.$host['host'], 'X-FORWARDED-SERVER:'.$host['host']));
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
// 28285730 是 songid
$comments = curl_get('http://music.163.com/api/v1/resource/comments/R_SO_4_28285730/?rid=R_SO_4_28285730&offset=0&total=true&limit=999999');
// 打印结果(数组)
print_r(json_decode($comments));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment