使用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();
Run Code Online (Sandbox Code Playgroud)
示例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."/>
Run Code Online (Sandbox Code Playgroud)
小智 13
我假设您正在尝试获取内容属性值,因此请尝试使用
$data = $crawler->filterXpath("//meta[@name='description']")->extract(array('content'));
Run Code Online (Sandbox Code Playgroud)
并循环$data.
$meta_description = $crawler->filter('meta[name="description"]')->eq(0)->attr('content');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3389 次 |
| 最近记录: |