複製代碼 代碼如下:
/* Author: Yang Yu */
//想看什麼電子書,先去新浪讀書搜尋,然後填入對應的參數即可
//http://vip.book.sina.com.cn/
//電子書參數
$array_book[0] = 38884; //小說id
$array_book[1] = 22172; //章節起始id
$array_book[2] = 32533; //章節結束id
$array_book[3] = '中國特種部隊生存實錄:狼牙'; //小說名字
//匹配參數
$title_pre = "/
(.*?)<\/h1>/"; //標題部分
$contents_pre = "/(.*?)<\/div>/"; //內容部分
//產生電子書
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 '第'.$i.'節抓取完畢< /br>';
}
fclose($fh);
}
http://www.bkjia.com/PHPjc/321104.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/321104.htmlTechArticle複製代碼 代碼如下: /* Author: Yang Yu yangyu@sina.cn */ //想看什麼電子書,先去新浪讀書搜尋,然後填入對應的參數即可 //http://vip.book.sina.com.cn...