php收罗百度MP3 TOP500歌曲

最近又写了php获取百度top500的歌曲名,因为百度歌曲的排行是及时更新的,写出了匹配法则后根基没什么大问题。就是下载需要时间较量长,百度top500的页面数据照旧挺大的。

功效图:

点击查察原图

上源码:

<?php $start_time = microtime(true); $url = 'http://list.mp3.baidu.com/top/top500.html'; $httptype = function_exists('curl_init'); if (!$httptype) { $html = file_get_contents($url); } else { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $html = curl_exec($ch); $info = curl_getinfo($ch); if ($html === false) echo "cURL Error: " . curl_error($ch); } $running_1 = microtime(true) - $start_time; echo '下载用时:'.number_format($running_1, 10, '.', '')."s<br />\n"; $search ='/<div><em[^>]+>(.*?)<\/em><\/div>.*?<div><i]*?)" title="[^"]*?">[^<]*?<\/i><\/div>.*?&word=([^\+"]+?)\+([^&"]*?)&lm=-1/is'; preg_match_all($search,$html,$r,PREG_SET_ORDER); $running_2 = microtime(true) - $start_time - $running_1; echo '匹配用时:'.number_format($running_2, 10, '.', '')."s<br />\n"; echo "<br />排名 - 歌名 - 歌手 <br /><br />\n"; foreach ($r as $v){ echo '<a href="http://mp3.baidu.com/m?word='.$v[3].'" target="_blank" title="百度一下“'.$v[3].'”"><img src="http://enenba.com/baidusort.gif" /></a> '; echo '<i>&nbsp;</i>'.$v[1].' - '.$v[3].' - '.$v[4]. '<br />'."\n"; } ?>

委曲上一个演示

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/7828.html