<?php
$url
=
"http://book.sina.com.cn/nzt/lit/zhuxian2/index.shtml"
;// 圖書地址
$ver
=
"old"
;
$r
=
file_get_contents
(
$url
);
preg_match(
"/<meta name=\"description\" content=\"(.*?)\">/is"
,
$r
,
$booktitle
);
$bookname
=
$booktitle
[1];
$preg
=
'/<li><a href=(.*).shtml target=_blank class=a03>/isU'
;
preg_match_all(
$preg
,
$r
,
$zj
);
$bookzj
=
count
(
$zj
[1]);
if
(
$ver
==
"new"
){
$content_start
=
"<!--正文內容開始-->"
;
$content_end
=
"<!--正文內容結束-->"
;
}
if
(
$ver
==
"old"
){
$content_start
=
"<\/table><!--NEWSZW_HZH_END-->"
;
$content_end
=
"<br>"
;
}
header(
"Content-Type:text/html;charset=gb2312"
);
writer(
$bookname
.
" 共"
.
$bookzj
.
"節\r\n帥哥劉並於"
.
date
(
"D M j G:i:s T Y"
).
"爲了畢業而設計小說整理收集\r\n"
,
"./ailaopo/"
.
$bookname
.
".txt"
,
"w+"
);
for
(
$i
=0;
$i
<
$bookzj
;
$i
++) {
$str
=
file_get_contents
(
"http://book.sina.com.cn"
.
$zj
[1][
$i
].
".shtml"
);
preg_match(
"/(<title>)(.*?)(<\/title>)/is"
,
$str
,
$title
);
$title
=
str_replace
(
"_讀書頻道_新浪網"
,
""
,
$title
[2]);
preg_match(
"/("
.
$content_start
.
")(.*?)("
.
$content_end
.
")/is"
,
$str
,
$content
);
$content
= preg_replace(
"/<(.*?)>/s"
,
""
,
str_replace
(
"</p>"
,
"\r\n"
,
$content
[2]));
print_r(
$content
);
exit
;
$result
=
" \r\n第"
.(
$i
+1).
"節--------"
.
$title
.
"_汪老師就是帥 --------- \r\n"
.
$content
;
writer(
$result
,
"./ailaopo/"
.
$bookname
.
".txt"
,
"a+"
);
echo
"小說"
.
$bookname
.
"共"
.
$bookzj
.
"節,現在整理到第"
.
$i
.
"節 _"
.
$title
.
"<br>"
;
}
echo
"小說"
.
$bookname
.
"共"
.
$bookzj
.
"節 已全部整理完成!"
;
function
writer(
$content
,
$url
,
$mode
)
{
$fp
=
fopen
(
$url
,
$mode
);
fwrite(
$fp
,
$content
);
fclose(
$fp
);
}
?>