如何刮取元标记的信息?

时间:2017-12-11 18:28:09

标签: node.js web-scraping css-selectors

我正在尝试使用Osmosis

来删除几个元标记的信息

元素如下所示:

<meta property="og:title" content="“here's the content!">

我看到了一段视频:

tag: "meta[property='og:title']@content"

所以我尝试了这样:

.find('head')
.set({
  description: "meta[property='og:title']@content"
})

但它对我的小项目不起作用。我真的不知道如何正确地做到这一点。

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

您可以使用以下方法获取相关元素:

var myMeta = document.querySelector('meta[property="og:title"]');

抓取它后,您可以使用以下内容访问其content

myMeta.content

工作示例:

var myMeta = document.querySelector('meta[property="og:title"]');

console.log(myMeta.content);
<meta property="og:title" content="here's the content!">

相关问题