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);
}