接着上篇文章,直接上源代码
header("Content-Type: text/html; charset=utf-8"); require_once "simple_html_dom.php"; $value="老男孩"; $result=find($value); function find($value) { $qurl='http://music.baidu.com/search?key='.$value;//搜索链接 $html1=file_get_html($qurl); $div=$html1->find('span[class=song-title]',0); $link1=$div->first_child ()->href;////获得第二步的http://music.baidu.com/song/5830696 $link2='http://music.baidu.com/'.$link1.'/download';//在后面加上/download $html2=file_get_html($link2);//解析这个页面,也就是下载的那个页面 $download=$html2->getElementById('download'); $url=$download->href;//获得想要的链接 $title=$html2->find('span[class=fwb]',0)->plaintext;//获得歌名 $author=$html2->find('span[class=author_list]',0)->plaintext;//获得歌手 return array('title'=>$title,'author'=>$author,'url'=>substr($url,22)); } //echo $link1."<br/>"; ."<br/>"; //echo substr($url,22); echo $result['title']."<br/>"; echo $result['author']."<br/>"; echo $result['url']; ?>