PHP - how to get main HTML content like Reader Mode in Firefox

前端 未结 5 1982
无人共我
无人共我 2021-02-11 06:33

in android Firefox app and safari iPad we can read only main content by \"Reader Mode\". read more... How to recognize only main content in HTML with PHP?

I need to dete

5条回答
  •  青春惊慌失措
    2021-02-11 07:07

    A new PHP library named PHP Goose seems to do a very good job at this too. It's pretty easy to use and is Composer friendly.

    Here's a usage example given on the actual readme :

    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();
    $movies = $article->getMovies();
    $articleText = $article->getCleanedArticleText();
    $entities = $article->getPopularWords();
    $image = $article->getTopImage();
    $allImages = $article->getAllImages();
    

提交回复
热议问题