簡體   English   中英

Symfony 的 DomCrawler 如何從 html 源中提取元描述

[英]Symfony's DomCrawler how can I extract meta description from html source

使用 Symfony 的 DomCrawler 如何從 html 源中提取元描述? http://symfony.com/doc/current/components/dom_crawler.html

$crawler = new Crawler();
$crawler->addHtmlContent($html->content, 'UTF-8');

$title = $crawler->filter('title')->text();

MSN 元描述示例

<meta name="description" content="The new MSN, Your customizable collection of the best in news, sports, entertainment, money, weather, travel, health, and lifestyle, combined with Outlook, Facebook, Twitter, Skype, and more."/>

我假設您正在嘗試獲取內容屬性值,因此請嘗試使用

$data = $crawler->filterXpath("//meta[@name='description']")->extract(array('content'));

並循環$data

$meta_description = $crawler->filter('meta[name="description"]')->eq(0)->attr('content');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM