yoozi / miner
PHP库,用于从公开网页中提取元数据并/或对其进行总结。
1.0.3
2014-07-24 08:56 UTC
Requires
- php: >=5.3.0
- illuminate/support: ~4.0
- jeremykendall/php-domain-parser: ~1.3
- kriswallsmith/buzz: ~0.10
Requires (Dev)
- phpunit/phpunit: 3.7.*
This package is not auto-updated.
Last update: 2024-09-28 16:36:23 UTC
README

此库是Golem项目的一部分,有关更多信息,请参阅yoozi/golem。
Miner是一个PHP库,可以从HTML页面中提取元数据和有趣文本内容(如作者、摘要等)。它类似于Apache Tika中的简化版HTML元数据解析器。
Miner是什么?
哇!看看下面从LinkedIn截取的截图
当你在LinkedIn上发布链接给你的联系人时,它将自动提取标题、摘要,甚至封面图片。Miner通常用于完成此类任务。
安装
安装Golem包最好的方法是使用Composer。
-
打开您的composer.json文件,并在require数组中添加以下内容
"yoozi/miner": "1.0.*" -
运行Composer以安装或更新新的包依赖项。
php composer install或者
php composer update
用法
解析器
- Meta:通过解析网页的HTML元标签来总结网页。在大多数情况下,它优先考虑Open Graph(OG)标记,并在必要时回退到标准元标签。
- 可读性:使用Arc90的可读性算法总结网页。所有功劳都归功于@feelinglucky的PHP端口。
- 混合:结合上述两种解析器,它将Readability作为主要解析器,将Meta作为回退。
混合默认启用。您可以根据需要更改解析器
// Use the Readability Parser. $extractor->getConfig()->set('parser', 'readability'); // Or...use the Hybrid Parser. // $extractor->getConfig()->set('parser', 'hybrid'); // Or...use the Meta Parser. // $extractor->getConfig()->set('parser', 'meta');
示例
我们可以解析远程URL并直接提取其元数据。
<?php use Yoozi\Miner\Extractor; use Buzz\Client\Curl; $extractor = new Extractor(); // Use the Hybrid Parser. $extractor->getConfig()->set('parser', 'hybrid'); // Strip all HTML tags in the description we parsed. $extractor->getConfig()->set('strip_tags', true); $meta = $extractor->fromUrl('http://www.example.com/', new Curl)->run(); var_dump($meta);
返回的数据
array(9) { ["title"]=> string(14) "Example Domain" ["author"]=> NULL ["keywords"]=> array(0) { } ["description"]=> string(220) " Example Domain This domain is established to be used for illustrative examples in documents. You may use this domain in examples without prior coordination or asking for permission. More information... " ["image"]=> NULL ["url"]=> string(23) "http://www.example.com/" ["host"]=> string(22) "http://www.example.com" ["domain"]=> string(11) "example.com" ["favicon"]=> string(52) "http://www.google.com/s2/favicons?domain=example.com" }
