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...