<?php //**************************************************************** $url = "http://book.sina.com.cn/nzt/lit/zhuxian2/index.shtml";// 圖書地址 $ver = "old"; //新舊版本 //**************************************************************** $r = file_get_contents($url); //用file_get_contents將網(wǎng)址打開并讀取所打開的頁面的內(nèi)容 preg_match("/<meta name=\"description\" content=\"(.*?)\">/is",$r,$booktitle);//匹配此頁面的標(biāo)題 $bookname = $booktitle[1];//取第二層數(shù)組 $preg = '/<li><a href=(.*).shtml target=_blank class=a03>/isU'; preg_match_all($preg, $r, $zj); //將此頁面的章節(jié)連接匹配出來 $bookzj = count($zj[1]);// 計(jì)算章節(jié)標(biāo)題數(shù)量 if ($ver=="new"){ $content_start = "<!--正文內(nè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ì)小說整理收集\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é)連接打開并讀取所打開的頁面的內(nèi)容 $str = file_get_contents("http://book.sina.com.cn".$zj[1][$i].".shtml"); preg_match("/(<title>)(.*?)(<\/title>)/is",$str,$title);//匹配此連接頁面的標(biāo)題 $title = str_replace("_讀書頻道_新浪網(wǎng)","",$title[2]);//把$title[2]里面有_讀書頻道_新浪網(wǎng)的換成空 preg_match("/(".$content_start.")(.*?)(".$content_end.")/is",$str,$content);//匹配此連接頁面的內(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 "小說".$bookname."共".$bookzj."節(jié),現(xiàn)在整理到第".$i."節(jié) _".$title."<br>"; } echo "小說".$bookname."共".$bookzj."節(jié) 已全部整理完成!"; function writer($content,$url,$mode)//定義函數(shù)名 writer 參數(shù)$content,$url,$mode { $fp = fopen($url, $mode);//打開文件$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
Guide: Stellar Blade Save File Location/Save File Lost/Not Saving
4 weeks ago
By DDD
Oguri Cap Build Guide | A Pretty Derby Musume
2 weeks ago
By Jack chen
Agnes Tachyon Build Guide | A Pretty Derby Musume
1 weeks ago
By Jack chen
Dune: Awakening - Advanced Planetologist Quest Walkthrough
3 weeks ago
By Jack chen
Date Everything: Dirk And Harper Relationship Guide
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)
