PHP Crawl Sina reading channel novel and generate txt ebook code _php example

Source: Internet
Author: User
Copy CodeThe code is as follows:
/* Author:yang Yu */
Want to see what ebook, first go to Sina study Search, and then fill in the corresponding parameters can
http://vip.book.sina.com.cn/
ebook Parameters
$array _book[0] = 38884; Fiction ID
$array _book[1] = 22172; Chapter Start ID
$array _book[2] = 32533; Chapter End ID
$array _book[3] = ' Chinese Special Forces Survival record: Spike '; Novel name

Matching parameters
$title _pre = "/

(. *?) <\/h1>/"; Title Section
$contents _pre = "/(. *?) <\/div>/"; Content section

//Generate e-book
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 ('

'," \ r \ n ", Str_replace ('

', ' ', $contents [1][0]))." \ r \ n ";
if (fwrite ($fh, $write _contents)) {
echo ' first ' $i. ' section crawl complete </br> ';
}
Fclose ($FH);
}

  • Related Article

    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.