Cheerio如何selectmeta标签获取内容值?

How to select the meta tags and get the content value in Cheerio?

我想 select 带有 og:title 属性 的元标记并从中获取内容文本值,即 Silver Surfer,我不知道如何处理这在 Cheerio

<meta property="og:type" content="SILVER" />
<meta property="og:image" content="http://img.silversurfer.com/surfer.png"/>
<meta property="og:title" content="Silver Surfer" />
<meta property="og:url" content="https://www.silversurfer.com" />

这是我迄今为止的最新尝试 var title = $('meta[property=og:title]').content

您需要使用属性 css 选择器并使用 Cheerio::attr.

获取属性
const cheerio = require('cheerio')
const $ = cheerio.load(`
<meta property="og:type" content="SILVER" />
<meta property="og:image" content="http://img.silversurfer.com/surfer.png"/>
<meta property="og:title" content="Silver Surfer" />
<meta property="og:url" content="https://www.silversurfer.com" />
`);

$('[property="og:type"]').attr('content');