Created
February 17, 2016 04:28
-
-
Save anonymous/550d8d595215ef0267dd to your computer and use it in GitHub Desktop.
获取网易云音乐歌曲评论
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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