I would like to select the meta tag with the og:title
property and get the content text value from it i.e. Silver Surfer
, I cannot figure how to approach this in 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" />
This is my latest attempt so far
var title = $('meta[property=og:title]').content
You need to use attribute css selector and to get the attribute use 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');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With