hstanleycrow/easyphparticleextractor

免费PHP库,用于从文章或新闻帖子中提取主要内容,包括图片和HTML

dev-main 2023-05-19 03:00 UTC

This package is auto-updated.

Last update: 2024-09-19 06:23:56 UTC


README


Easy PHP Article Extractor

这是一个PHP文章和新闻帖子提取库。此库可以检测HTML中的内容位置,并从页面中读取文章内容,保留所有有用的HTML,适合翻译和在其他语言中发布。

您也可以仅提取文本。该库可以移除所有内部链接,避免这些链接进入内容。它还会处理图片以移除链接。关于图片,该库提取所有支持的HTML标签中的图片,以及将图片添加到帖子内容中的方法。

该库还可以检测YouTube视频,并将视频URL注入到内容的正确位置,避免手动操作,并以此方式处理插入的推文。

对于我开发的一个项目,我发现许多现有的开源解决方案,但每个都对我的项目有独特的失败。您可以使用这个库与我的另一个库结合使用,该库使用Google翻译API进行翻译:EasyPHPGoogleTranslate

此库的另一个用途是将其与另一个库结合使用,该库从PHP发布内容到Wordpress:EasyPHPToWordpress。这样,您可以从PHP提取、翻译并发布到Wordpress。我还开发了一个库:EasyPHPOpenAI,您可以在其中使用它来在提取的内容中使用OpenAI API。

免费PHP库,用于从文章或新闻帖子中提取主要内容,包括图片和HTML

如何使用下载许可协议

如何使用

# Clone this repository
$ git clone https://github.com/hstanleycrow/EasyPHPArticleExtractor/

# install libraries
$ composer update

# Install using composer
$ composer require hstanleycrow/easyphparticleextractor

### Using Examples
You only need to create an instance of the main class with the URL with the content to extract and you will to obtain the content with the HTML, in plain text and the title of the article.
PD: I use the library to extract the content with HTML, so the plain text is not my priority. In the other hand, the detection of the main content is very hard, so, sometimes it can extract weird content with the main post, but this library was developed to use the extracted content with an text editor, so, extract some garbage is not a problem for me, because in the editor the user can clean the content.

```php
$url = 'https://nftplazas.com/zed-run-airdrop/';
$articleExtractor = new ArticleExtractor($url);
$article = $articleExtractor->article();
$title = $articleExtractor->title();
$plaintext = $articleExtractor->plainText();

$url = 'https://www.seroundtable.com/google-search-algorithm-ranking-volatility-35414.html';
$article = $articleExtractor->article();
echo $articleExtractor->title() . PHP_EO

下载

您可以通过这里下载最新版本。

PHP版本

我仅在以下PHP版本中测试了这个类。因此,如果您有较旧版本且无法工作,请告诉我。

支持

Buy Me A Coffee

许可协议

MIT

www.hablemosdeseo.net  ·  GitHub @hstanleycrow  ·  Twitter @harold_crow