<?php //**************************************************************** $url = "http://book.sina.com.cn/nzt/lit/zhuxian2/index.shtml";// 图书地址 $ver = "old"; //新旧版本 //**************************************************************** $r = file_get_contents($url); //用file_get_contents将网址打开并读取所打开的页面的内容 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++) { //echo "http://book.sina.com.cn".$zj[1][$i]".shtml";die(); //用file_get_contents将章节连接打开并读取所打开的页面的内容 $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]);//把$title[2]里面有_读书频道_新浪网的换成空 preg_match("/(".$content_start.")(.*?)(".$content_end.")/is",$str,$content);//匹配此连接页面的内容 $content = preg_replace("/<(.*?)>/s","",str_replace("</p>","\r\n",$content[2]));//用str_replace把$content[2]里有</p> 的换成\r\n print_r($content); exit; //把第".($i+1)."节和标题与内容连接在一起放在变量 $result = " \r\n第".($i+1)."节--------".$title."_汪老师就是帅 --------- \r\n".$content; writer($result, "./ailaopo/".$bookname.".txt","a+");//调用函数把$result echo "小说".$bookname."共".$bookzj."节,现在整理到第".$i."节 _".$title."<br>"; } echo "小说".$bookname."共".$bookzj."节 已全部整理完成!"; function writer($content,$url,$mode)//定义函数名 writer 参数$content,$url,$mode { $fp = fopen($url, $mode);//打开文件$url fwrite($fp, $content);//把$content放入到$fp fclose($fp); //关闭$fp } ?>
Statement
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

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

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

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article
Assassin's Creed Shadows: Seashell Riddle Solution
3 weeks agoByDDD
What's New in Windows 11 KB5054979 & How to Fix Update Issues
3 weeks agoByDDD
Where to find the Crane Control Keycard in Atomfall
3 weeks agoByDDD
Roblox: Dead Rails - How To Complete Every Challenge
4 weeks agoByDDD
Atomfall guide: item locations, quest guides, and tips
1 months agoByDDD

Hot Tools

Dreamweaver Mac version
Visual web development tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

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

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver CS6
Visual web development tools
