PHP Crawler Crawl Lyrics

Source: Internet
Author: User
This article introduces the content is about the PHP crawler crawl lyrics, has a certain reference value, now share to everyone, the need for friends can refer to

<?phpheader ("Content-type:text/html;charset=utf-8"), class small_crawler{protected $regular;           Get content regular protected $url;             source protected $i;         Control quantity protected $count;     Total protected $lyrics _ze;    Lyrics content protected $lyrics _LRC;           Lyrics address matching protected $txt;        Storage address function __construct () {$this->regular = "/<a href=\" \/song\/([0-9]) *\ ". *>*<\/a>/";        $this->lyrics_ze = "/<p id=\" lyriccont\ ". *<\/p>/";        $this-&GT;LYRICS_LRC = "/\" http:\/\/.*\ "/";        $this->url = ' http://music.baidu.com/';        $this->txt = "Playlist.txt";        $this->i = 0;    $this->count = 110;        }/** * Start Task */function perform () {$data = file_get_contents ($this->url); if (Preg_match_all ($this->regular, $data, $mar)) {$this->lyrics ($mar);//Lyrics Filtering}else{Ech            O ' no information available ';        Exit }}/** * @paRam $data * Lyrics processing * * Function lyrics ($data) {if (Is_array ($data)) {//Lyrics filter FOREAC                H ($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);                }}}}//Loop operation 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);//Song    Word Filter}}}}}/** * @param $lyrics _file * * Write to 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;//End Stop}}}//run $ts = new Small_crawler (); $ts->perform ()?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.