欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP 抓取新浪讀書頻道的小說(shuō)并生成txt電子書的代碼

 更新時(shí)間:2009年12月18日 22:08:03   作者:  
想看什么電子書,先去新浪讀書搜索,然后填入對(duì)應(yīng)的參數(shù)即可
復(fù)制代碼 代碼如下:

/* Author: Yang Yu <yangyu@sina.cn> */
//想看什么電子書,先去新浪讀書搜索,然后填入對(duì)應(yīng)的參數(shù)即可
//http://vip.book.sina.com.cn/
//電子書參數(shù)
$array_book[0] = 38884; //小說(shuō)id
$array_book[1] = 22172; //章節(jié)起始id
$array_book[2] = 32533; //章節(jié)結(jié)束id
$array_book[3] = '中國(guó)特種部隊(duì)生存實(shí)錄:狼牙'; //小說(shuō)名字

//匹配參數(shù)
$title_pre = "/<h1>(.*?)<\/h1>/"; //標(biāo)題部分
$contents_pre = "/<div id=\"contTxt\" class=\"contTxt1\">(.*?)<\/div>/"; //內(nèi)容部分

//生成電子書
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.'節(jié)抓取完畢< /br>';
}
fclose($fh);
}

相關(guān)文章

最新評(píng)論