PHP crawls the novels of Sina reading channel and generates the txt e-book code _ php instance

Source: Internet
Author: User
If you want to read any ebook, go to Sina reading and search, and enter the corresponding parameters. 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 );
}

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.