<?php //**************************************************************** $url = "http://book.sina.com.cn/nzt/lit/zhuxian2/index.shtml";// 圖書(shū)地址 $ver = "old"; //新舊版本 //**************************************************************** $r = file_get_contents($url); //用file_get_contents將網(wǎng)址打開(kāi)并讀取所打開(kāi)的頁(yè)面的內(nèi)容 preg_match("/<meta name=\"description\" content=\"(.*?)\">/is",$r,$booktitle);//匹配此頁(yè)面的標(biāo)題 $bookname = $booktitle[1];//取第二層數(shù)組 $preg = '/<li><a href=(.*).shtml target=_blank class=a03>/isU'; preg_match_all($preg, $r, $zj); //將此頁(yè)面的章節(jié)連接匹配出來(lái) $bookzj = count($zj[1]);// 計(jì)算章節(jié)標(biāo)題數(shù)量 if ($ver=="new"){ $content_start = "<!--正文內(nèi)容開(kāi)始-->"; $content_end = "<!--正文內(nèi)容結(jié)束-->"; } if ($ver=="old"){ $content_start = "<\/table><!--NEWSZW_HZH_END-->"; $content_end = "<br>"; } header("Content-Type:text/html;charset=gb2312"); writer($bookname." 共".$bookzj."節(jié)\r\n帥哥劉并于".date("D M j G:i:s T Y")."為了畢業(yè)而設(shè)計(jì)小說(shuō)整理收集\r\n", "./ailaopo/".$bookname.".txt","w+"); for ($i=0;$i<$bookzj;$i++) { //echo "http://book.sina.com.cn".$zj[1][$i]".shtml";die(); //用file_get_contents將章節(jié)連接打開(kāi)并讀取所打開(kāi)的頁(yè)面的內(nèi)容 $str = file_get_contents("http://book.sina.com.cn".$zj[1][$i].".shtml"); preg_match("/(<title>)(.*?)(<\/title>)/is",$str,$title);//匹配此連接頁(yè)面的標(biāo)題 $title = str_replace("_讀書(shū)頻道_新浪網(wǎng)","",$title[2]);//把$title[2]里面有_讀書(shū)頻道_新浪網(wǎng)的換成空 preg_match("/(".$content_start.")(.*?)(".$content_end.")/is",$str,$content);//匹配此連接頁(yè)面的內(nèi)容 $content = preg_replace("/<(.*?)>/s","",str_replace("</p>","\r\n",$content[2]));//用str_replace把$content[2]里有</p> 的換成\r\n print_r($content); exit; //把第".($i+1)."節(jié)和標(biāo)題與內(nèi)容連接在一起放在變量 $result = " \r\n第".($i+1)."節(jié)--------".$title."_汪老師就是帥 --------- \r\n".$content; writer($result, "./ailaopo/".$bookname.".txt","a+");//調(diào)用函數(shù)把$result echo "小說(shuō)".$bookname."共".$bookzj."節(jié),現(xiàn)在整理到第".$i."節(jié) _".$title."<br>"; } echo "小說(shuō)".$bookname."共".$bookzj."節(jié) 已全部整理完成!"; function writer($content,$url,$mode)//定義函數(shù)名 writer 參數(shù)$content,$url,$mode { $fp = fopen($url, $mode);//打開(kāi)文件$url fwrite($fp, $content);//把$content放入到$fp fclose($fp); //關(guān)閉$fp } ?>
Statement of this Website
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

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article
How to fix KB5060533 fails to install in Windows 10?
4 weeks ago
By DDD
Dune: Awakening - Where To Get Insulated Fabric
3 weeks ago
By Jack chen
Gmail Login: How to Sign Up, Sign In, or Sign Out of Gmail - MiniTool
1 months ago
By Jack chen
How to fix KB5060999 fails to install in Windows 11?
3 weeks ago
By DDD
Guild Guide In Tainted Grail: The Fall Of Avalon
4 weeks ago
By Jack chen

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
