[英]Symfony's DomCrawler how can I extract meta description from html source
Using Symfony's DomCrawler how can I extract meta description from html source?使用 Symfony 的 DomCrawler 如何从 html 源中提取元描述? http://symfony.com/doc/current/components/dom_crawler.html
http://symfony.com/doc/current/components/dom_crawler.html
$crawler = new Crawler();
$crawler->addHtmlContent($html->content, 'UTF-8');
$title = $crawler->filter('title')->text();
Example MSN meta description 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."/>
I assume you are trying to get content attribute value so try to use我假设您正在尝试获取内容属性值,因此请尝试使用
$data = $crawler->filterXpath("//meta[@name='description']")->extract(array('content'));
and loop through $data
.并循环
$data
。
$meta_description = $crawler->filter('meta[name="description"]')->eq(0)->attr('content');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.