php laravel 轻松自动提取网页内容

2022-10-27  本文已影响0人  大萝卜2022

安装

composer require fivefilters/readability.php

代码

use andreskrey\Readability\Readability;
use andreskrey\Readability\Configuration;
use andreskrey\Readability\ParseException;

$readability = new Readability(new Configuration());

$html = file_get_contents('http://your.favorite.newspaper/article.html');

try {
    $readability->parse($html);
    echo $readability;
} catch (ParseException $e) {
    echo sprintf('Error processing text: %s', $e->getMessage());
}


上一篇下一篇

猜你喜欢

热点阅读