PHP實現(xiàn)的抓取小說網(wǎng)站內(nèi)容功能示例
本文實例講述了PHP實現(xiàn)的抓取小說網(wǎng)站內(nèi)容功能。分享給大家供大家參考,具體如下:
爬取免費內(nèi)容,弄到手機(jī),聽書,妥妥的。
ini_set('user_agent','Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; GreenBrowser)'); ini_set('max_execution_time', '0'); $base = 'https://www.qu.la/book/19434/'; $start = '7504808.html'; $content_grep = '/ (.*)<br\/>/'; //$content_grep = '/<div id="content">(.*)<br\/>/sS'; $next_grep = '/<a id="pager_next" href=\"(\d+\.html)\" target="_top" class="next">下一章<\/a>/'; $next = $start; $file_name = '聽書了.txt'; while($next) { echo 'getting ' . $next . PHP_EOL; $result = file_get_contents($base . $next); preg_match_all($content_grep, $result, $match); $isTitle = true; $content = ""; foreach($match[1] as $line) { $line = str_replace("<br/>", '', $line); $line = str_replace(" ", '', $line); if($isTitle) { $content = $line . PHP_EOL . PHP_EOL; $isTitle = false; } else { $content .= ' ' . $line . PHP_EOL . PHP_EOL; } } $file = fopen($file_name, 'a'); echo 'write length: ' . strlen($content) . PHP_EOL; fwrite($file, $content); fclose($file); echo '.'; preg_match($next_grep, $result, $match); $next = $match[1]; }
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php socket用法總結(jié)》、《php字符串(string)用法總結(jié)》、《PHP數(shù)學(xué)運算技巧總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計入門教程》、《PHP數(shù)組(Array)操作技巧大全》、《PHP數(shù)據(jù)結(jié)構(gòu)與算法教程》、《php程序設(shè)計算法總結(jié)》及《PHP網(wǎng)絡(luò)編程技巧總結(jié)》
希望本文所述對大家PHP程序設(shè)計有所幫助。
相關(guān)文章
PHP擴(kuò)展mcrypt實現(xiàn)的AES加密功能示例
這篇文章主要介紹了PHP擴(kuò)展mcrypt實現(xiàn)的AES加密功能,結(jié)合實例形式分析了php基于mcrypt實現(xiàn)AES加密的相關(guān)操作技巧,需要的朋友可以參考下2019-01-01PHP錯誤提示It is not safe to rely on the system……的解決方法
今天小編就為大家分享一篇關(guān)于PHP錯誤提示It is not safe to rely on the system……的解決方法,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2019-03-03PHP中函數(shù)gzuncompress無法使用的解決方法
這篇文章主要介紹了PHP中函數(shù)gzuncompress無法使用的解決方法,文中的介紹的很詳細(xì),需要的朋友可以參考借鑒,下面來一起看看吧。2017-03-03