如何使用Goutte获取元描述内容 [英] How to get meta description content using Goutte

查看:86
本文介绍了如何使用Goutte获取元描述内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

能帮我找到一种使用Goutte从元描述,元关键字和机器人内容中获取内容的方法吗?另外,如何定位<link rel="stylesheet" href=""><script>?

Can you please help me to find a way to get a content from meta description, meta keywords and robots content using Goutte. Also, how can I target <link rel="stylesheet" href=""> and <script>?

下面是我用来获取<title>内容的PHP:

Below is PHP that I used to get <title> content:

require_once 'goutte.phar';

use Goutte\Client;

$client = new Client();


$crawler = $client->request('GET', 'http://stackoverflow.com/');

$crawler->filter('title')->each(function ($node) {
$content .= "Title: ".$node->text()."";
echo $content;
});

这里是Goutte的链接- https://github.com/fabpot/goutte

Here is a link to Goutte - https://github.com/fabpot/goutte

推荐答案

您可以使用:

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

这篇关于如何使用Goutte获取元描述内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆