j0k3r/php-readability
Composer 安装命令:
composer require j0k3r/php-readability
包简介
Automatic article extraction from HTML
README 文档
README
This is an extract of the Readability class from this full-text-rss fork. It can be defined as a better version of the original php-readability.
Differences
The default php-readability lib is really old and needs to be improved. I found a great fork of full-text-rss from @Dither which improve the Readability class.
- I've extracted the class from its fork to be able to use it out of the box
- I've added some simple tests
- and changed the CS, run
php-cs-fixerand added a namespace
But the code is still really hard to understand / read ...
Requirements
By default, this lib will use the Tidy extension if it's available. Tidy is only used to cleanup the given HTML and avoid problems with bad HTML structure, etc .. It'll be suggested by Composer.
Also, if you got problem from parsing a content without Tidy installed, please install it and try again.
Usage
use Readability\Readability; $url = 'http://www.medialens.org/index.php/alerts/alert-archive/alerts-2013/729-thatcher.html'; // you can use whatever you want to retrieve the html content (Guzzle, Buzz, cURL ...) $html = file_get_contents($url); $readability = new Readability($html, $url); // or without Tidy // $readability = new Readability($html, $url, 'libxml', false); $result = $readability->init(); if ($result) { // display the title of the page echo $readability->getTitle()->textContent; // display the *readability* content echo $readability->getContent()->textContent; } else { echo 'Looks like we couldn\'t find the content. :('; }
If you want to debug it, or check what's going on, you can inject a logger (which must follow Psr\Log\LoggerInterface, Monolog for example):
use Readability\Readability; use Monolog\Logger; use Monolog\Handler\StreamHandler; $url = 'http://www.medialens.org/index.php/alerts/alert-archive/alerts-2013/729-thatcher.html'; $html = file_get_contents($url); $logger = new Logger('readability'); $logger->pushHandler(new StreamHandler('path/to/your.log', Logger::DEBUG)); $readability = new Readability($html, $url); $readability->setLogger($logger);
j0k3r/php-readability 适用场景与选型建议
j0k3r/php-readability 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 902.78k 次下载、GitHub Stars 达 184, 最近一次更新时间为 2014 年 12 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「html」 「extraction」 「content」 「article」 「article extraction」 「content extraction」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 j0k3r/php-readability 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 j0k3r/php-readability 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 j0k3r/php-readability 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Extract, Transform and Load data using PHP.
Texy converts plain text in easy to read Texy syntax into structurally valid (X)HTML. It supports adding of images, links, nested lists, tables and has full support for CSS. Texy supports hyphenation of long words (which reflects language rules), clickable emails and URL (emails are obfuscated again
A block that displays featured content - large image, title, description and link.
Library for merging source data to destination data only if destination data remains valid after that
PHP Interface for Babel Street Text Analytics
TYPO3 CMS extension to create gallery content element with preset crop ratios and pagination
统计信息
- 总下载量: 902.78k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 190
- 点击次数: 25
- 依赖项目数: 6
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2014-12-12