Home >Backend Development >PHP Tutorial >PHP code to grab novels from Sina Reading Channel and generate txt e-books_PHP Tutorial

PHP code to grab novels from Sina Reading Channel and generate txt e-books_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 15:41:391567browse

Copy code The code is as follows:

/* Author: Yang Yu */
// To find out what e-book you want to read, first go to Sina Reading to search, and then fill in the corresponding parameters
//http://vip.book.sina.com.cn/
//e-book parameters
$array_book[0] = 38884; //Novel id
$array_book[1] = 22172; //Chapter start id
$array_book[2] = 32533; //Chapter end id
$array_book [3] = 'Chinese Special Forces Survival Record: Langya'; //Novel name

//Matching parameters
$title_pre = "/

(.*?)$contents_pre = "/
(.*?)
/"; //Content part

//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]."rn".str_replace('

',"rn",str_replace('

',' ',$contents[1][0])). "rn";
if( fwrite($fh,$write_contents) ){
echo 'Section '.$i.' has been fetched< /br>';
}
fclose ($fh);
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/321104.htmlTechArticleCopy the code as follows: /* Author: Yang Yu yangyu@sina.cn */ //What electronics do you want to see? For books, first go to Sina Reading to search, and then fill in the corresponding parameters // http://vip.book.sina.com.cn...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn