PHP Crawl Sina Reading channel's novel and Generate txt ebook code _php instance

Source: Internet
Author: User
Copy Code code 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
http://vip.book.sina.com.cn/
ebook Parameters
$array _book[0] = 38884; Novel ID
$array _book[1] = 22172; Chapter Start ID
$array _book[2] = 32533; Chapter End ID
$array _book[3] = ' China Special Forces Survival record: Spike '; Novel name

Matching parameters
$title _pre = "/$contents _pre = "/<div id=\" conttxt\ "class=\" conttxt1\ "> (. *?) <\/div>/"; Content section

Generate E-books
for ($i = $array _book[1]; $i <= $array _book[2]; $i + +) {
$url = "http://vip.book.sina.com.cn/book/chapter_{$array _book[0]}_{$i}.html";
$html = file_get_contents ($url);
Preg_match_all ($title _pre, $html, $title);
Preg_match_all ($contents _pre, $html, $contents);
$fh = fopen ($array _book[3]. TXT ', ' A + ');
$write _contents = $title [1][0]. " \ r \ n ". Str_replace (' </p> '," \ r \ n '), Str_replace (' <p> ', ' ", $contents [1][0])." \ r \ n ";
if (fwrite ($fh, $write _contents)) {
Echo ' $i. ' The/br> is finished < ';
}
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.