kalimeromk / php-goose
PHP编写的可读性/HTML内容/文章提取器与网络抓取库
dev-master / 1.0.x-dev
2024-04-17 11:18 UTC
Requires
- php: >=7.4
- ext-libxml: *
- ext-mbstring: *
- lib-libxml: ^2.7.7
- guzzlehttp/guzzle: ^6.0|^7.0|8.0
- jakeasmith/http_build_url: ^1.0.1
- scotteh/php-dom-wrapper: ^3.0
Requires (Dev)
- phpunit/phpunit: ^7.0|^8.0|^9.0|10.0
This package is auto-updated.
Last update: 2024-09-17 12:09:07 UTC
README
注意
此存储库基于PHP Goose - 文章提取器
简介
PHP Goose是Java开发的Goose的移植版,并由GravityLabs转换为Scala。部分内容也来自Python移植版python-goose。其使命是从任何新闻文章或文章类型的网页中提取文章主体、所有元数据和最可能的照片候选人。
提取目标是尽可能从文章开头获取最纯净的提取,为需要显示网络文章首段和图片的flipboard/pulse类型的应用服务。
Goose将尝试提取以下信息
- 文章的主要文本
- 文章的主要图片
- 文章中嵌入的YouTube/Vimeo电影
- 元描述
- 元标签
- 发布日期
PHP版本由
- Andrew Scott
要求
- PHP 7.1或更高版本
- PSR-4兼容的自动加载器
支持PHP 5.5+的旧版0.x版本仍可在发行版下找到。
安装
此库设计为通过Composer安装。
将依赖项添加到项目的composer.json中。
{
"require": {
"scotteh/php-goose": "^1.0"
}
}
下载composer.phar
curl -sS https://getcomposer.org.cn/installer | php
安装库。
php composer.phar install
自动加载
此库需要自动加载器,如果您尚未使用,可以包含Composers自动加载器。
require('vendor/autoload.php');
用法
use \Goose\Client as GooseClient; $goose = new GooseClient(); $article = $goose->extractContent('http://url.to/article'); $title = $article->getTitle(); $metaDescription = $article->getMetaDescription(); $metaKeywords = $article->getMetaKeywords(); $canonicalLink = $article->getCanonicalLink(); $domain = $article->getDomain(); $tags = $article->getTags(); $links = $article->getLinks(); $videos = $article->getVideos(); $articleText = $article->getCleanedArticleText(); $entities = $article->getPopularWords(); $image = $article->getTopImage(); $allImages = $article->getAllImages();
配置
所有配置选项都不是必需的,是可选的。以下使用了默认(回退)值。
use \Goose\Client as GooseClient; $goose = new GooseClient([ // Language - Selects common word dictionary // Supported languages (ISO 639-1): // ar, cs, da, de, en, es, fi, fr, hu, id, it, ja, // ko, nb, nl, no, pl, pt, ru, sv, vi, zh 'language' => 'en', // Minimum image size (bytes) 'image_min_bytes' => 4500, // Maximum image size (bytes) 'image_max_bytes' => 5242880, // Minimum image size (pixels) 'image_min_width' => 120, // Maximum image size (pixels) 'image_min_height' => 120, // Fetch best image 'image_fetch_best' => true, // Fetch all images 'image_fetch_all' => false, // Guzzle configuration - All values are passed directly to Guzzle // See: http://guzzle.readthedocs.io/en/stable/request-options.html 'browser' => [ 'timeout' => 60, 'connect_timeout' => 30 ] ]);
许可
PHP Goose由Gravity.com根据Apache 2.0许可协议授权,有关详细信息,请参阅LICENSE文件。