Skip to content

Instantly share code, notes, and snippets.

@bactisme
Last active June 7, 2023 12:41
Show Gist options
  • Save bactisme/3f5c3a7e51690c71a72bfe5628002474 to your computer and use it in GitHub Desktop.
Save bactisme/3f5c3a7e51690c71a72bfe5628002474 to your computer and use it in GitHub Desktop.
Google Sheet formula to extract a page FAQ description
// ADD CHEERIO LIBRARY
// Script ID : 1ReeQ6WO8kKNxoaA_O0XEQ589cIrRvEBA9qcWpNqdOP17i47u6N9M5Xh0
function extractMetaFAQ(url) {
// Récupérez le flux RSS
var response = UrlFetchApp.fetch(url);
var html = response.getContentText();
const $ = Cheerio.load(html);
var obj = JSON.parse($('script.yoast-schema-graph').html());
//console.log(obj);
var ret = [];
for(var i = 0; i < obj["@graph"].length; i++){
if (obj["@graph"][i]["@type"] == "Question"){
var q = obj["@graph"][i];
ret.push(q["name"]+" ("+q["acceptedAnswer"]["text"].length+" signes)");
}
}
return ret.join("\n");
}
// call with formula
// =extratDateMeta(C2;"article:modified_time")
function extratDateMeta(url, metaname){
var response = UrlFetchApp.fetch(url);
var html = response.getContentText();
const $ = Cheerio.load(html);
var meta = $("[property="+metaname+"]").attr("content");
return new Date(meta.replace("T", " "));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment