Jason
Jason

Reputation: 1678

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? 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

<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."/>

Upvotes: 11

Views: 6921

Answers (2)

Luca Filosofi
Luca Filosofi

Reputation: 31173

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

Upvotes: 6

xamoxer1
xamoxer1

Reputation: 180

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.

Upvotes: 15

Related Questions