Skip to content

Instantly share code, notes, and snippets.

@lizheming
Created November 6, 2012 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lizheming/4025195 to your computer and use it in GitHub Desktop.
Save lizheming/4025195 to your computer and use it in GitHub Desktop.
虾米已加载歌曲ID抓取
<?php
set_time_limit(0); //设置成不限制页面运行时间
$page = ''; //填写你的已经下载页面的页数
$cookie_file = dirname(__FILE__).'/cookie.txt';
$song = '';
//如果页数过多可以分批获取,以免等待时间过长
for($i=1;$i<=$page;$i++) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://www.xiami.com/account/mysongs/s/2/page/".$i);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie_file);
$data = curl_exec($curl);
curl_close($curl);
$preg = '/\<td.class\=\"iname\"\>\<a.href\=\"\/song\/(.*?)\"\>(.*?)\<\/a\>/s';
preg_match_all($preg, $data, $match);
foreach($match[1] as $item) {
$song .= $item . ',';
}
}
$song = str_replace(' ', '', $song);
$song = substr($song, 0, -1);
echo 'var song = new Array(' . $song . ');';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment