《php教程之PHP從HTML中提取正文類庫》要點(diǎn):
本文介紹了php教程之PHP從HTML中提取正文類庫,希望對(duì)您有用。如果有疑問,可以聯(lián)系我們。
An efficient class library for extracting text from HTML.
一個(gè)高效的從HTML中提取正文的類庫.
正文提取采納了基于文本密度的提取算法,支持從壓縮的HTML文檔中提取正文,每個(gè)頁面平均提取時(shí)間為30ms,正確率在95%以上.
特色
標(biāo)簽無關(guān),提取正文不依賴標(biāo)簽;
支持從壓縮的HTML文檔中提取正文內(nèi)容;
支持帶標(biāo)簽輸出原始正文;
核心算法簡潔高效,平均提取時(shí)間在30ms左右.
安裝
安裝包文件
composer require "mylukin/textractor:dev-master"
添加 ServiceProvider
到您項(xiàng)目 config/app.php
中的 providers
部門:
Lukin\Textractor\TextractorServiceProvider::class,
創(chuàng)立配置文件:
php artisan vendor:publish --provider="Lukin\Textractor\TextractorServiceProvider"
然后請(qǐng)修改 config/textractor.php
中對(duì)應(yīng)的項(xiàng)即可.
使用
<?php$url = 'http://news.163.com/17/0204/08/CCDTBQ9E000189FH.html';// 創(chuàng)立提取實(shí)例$textractor = new \Lukin\Textractor\Textractor();// 下載并解析文章$article = $textractor->download($url)->parse();printf('<div id="url">URL: %s</div>' . PHP_EOL, $url);printf('<div id="title">Title: %s</div>' . PHP_EOL, $article->getTitle());printf('<div id="published">Publish: %s</div>' . PHP_EOL, $article->getPublishDate());printf('<div id="text">Text: <pre>%s</pre></div>' . PHP_EOL, $article->getText());printf('<div id="html">Content: %s</div>' . PHP_EOL, $article->getHTML());
地址:https://github.com/mylukin/Textractor
《php教程之PHP從HTML中提取正文類庫》是否對(duì)您有啟發(fā),歡迎查看更多與《php教程之PHP從HTML中提取正文類庫》相關(guān)教程,學(xué)精學(xué)透。維易PHP學(xué)院為您提供精彩教程。
轉(zhuǎn)載請(qǐng)注明本頁網(wǎng)址:
http://www.snjht.com/jiaocheng/7194.html