PHP crawler captures lyrics

不言
Release: 2023-03-23 21:52:01
Original
1403 people have browsed it

The content of this article is about PHP crawler crawling lyrics, which has certain reference value. Now I share it with everyone. Friends in need can refer to it

regular = "/*<\/a>/"; $this->lyrics_ze = "/

/"; $this->lyrics_lrc = "/\"http:\/\/.*\"/"; $this->url = 'http://music.baidu.com/'; $this->txt = "playlist.txt"; $this->i = 0; $this->count = 110; } /** * 开始任务 */ function perform() { $data = file_get_contents($this->url); if(preg_match_all($this->regular, $data, $mar)){ $this->lyrics($mar); //歌词筛选 }else{ echo '已没有可用信息'; exit; } } /** * @param $data * 歌词处理 */ function lyrics($data) { if(is_array($data)){ //歌词筛选 foreach ($data[0] as $k=>$y){ $data_s = explode('"',$y); if(!empty($data_s[1])){ $the_lyrics = file_get_contents($this->url.$data_s[1]); if(preg_match_all($this->lyrics_ze, $the_lyrics, $lyrics_x)){ if(preg_match_all($this->lyrics_lrc, $lyrics_x[0][0], $lyrics_c)){ $lyrics_c = explode('"',$lyrics_c[0][0]); $lyrics_file = file_get_contents($lyrics_c[1]); $this->write($lyrics_file); } } } } //循环操作 foreach ($data[0] as $ki=>$yi){ $data_t = explode('"',$yi); if(!empty($data_t[1])){ $the_lyrics_as = file_get_contents($this->url.$data_t[1]); if(preg_match_all($this->regular, $the_lyrics_as, $mars)){ $this->lyrics($mars); //歌词筛选 } } } } } /** * @param $lyrics_file * 写入文件 */ function write($lyrics_file) { if($this->i < $this->count){ $acs = preg_replace('/(\[.*\])/','',$lyrics_file); $myfile = fopen($this->txt, "a"); fwrite($myfile,$acs); fwrite($myfile,"\r\n".$this->i.".-----------------------------------------------------------\r\n"); $this->i++; }else{ exit; //结束停止 } } } //运行 $ts = new Small_crawler(); $ts->perform() ?>

Copy after login

Related recommendations:

Use php crawler to analyze Nanjing housing prices

php crawler captures Baidu Tieba pictures



The above is the detailed content of PHP crawler captures lyrics. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!