PHP crawls the novels of Sina's reading channel and generates the code for the txt ebook _ PHP Tutorial

Source: Internet
Author: User
PHP captures the novels of Sina reading channel and generates the txt e-book code. Copy the code as follows: * Author: YangYuyangyu@sina.cn * want to see what eBook, go to Sina reading search, and then fill in the corresponding parameters vip.book.sina.com.cn The code is as follows:


/* Author: Yang Yu */
// You can search for any ebook on Sina first, and then enter the corresponding parameters.
// Http://vip.book.sina.com.cn/
// E-book parameters
$ Array_book [0] = 38884; // novel id
$ Array_book [1] = 22172; // unit start id
$ Array_book [2] = 32533; // Chapter end id
$ Array_book [3] = 'survival record of special forces in China: Langya '; // novel name

// Match parameters
$ Title_pre = "/(.*?) <\/H1>/"; // title
$ Contents_pre = "/

(.*?) <\/P>/"; // content section

// Generate an e-book
For ($ I = $ array_book [1]; $ I <= $ array_book [2]; $ I ++ ){
$ Url = "http://vip.book.sina.com.cn/book/chapter_{$array_book1_01_1_1__1_i1_.html ";
$ Html = file_get_contents ($ url );
Preg_match_all ($ title_pre, $ html, $ title );
Preg_match_all ($ contents_pre, $ html, $ contents );
$ Fh = fopen($array_book%32.16.'.txt ', 'A + ');
$ Write_contents = $ title [1] [0]. "\ r \ n". str_replace ('

', "\ R \ n", str_replace ('

', '', $ Contents [1] [0])." \ r \ n ";
If (fwrite ($ fh, $ write_contents )){
Echo 'segment '. $ I.' is crawled. </br> ';
}
Fclose ($ fh );
}

Http://www.bkjia.com/PHPjc/321104.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/321104.htmlTechArticle code is as follows:/* Author: Yang Yu yangyu@sina.cn * // want to see what eBook, first go to Sina reading search, and then fill in the corresponding parameters can be // http://vip.book.sina.com.cn...

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.