I'm fetching the HTML from this url. I'm interested in these are two lines:
<meta name="SAC:price" content="444000">
<meta name="SAC:published" content="2020-03-28 11:06:22">
I want to extract the content value of those two lines. In this example my desired output is
[444000, 2020-03-28 11:06:22]
What is the simplest way to do this? This is what I've tried so far:
function myFunction() {
var url = "https://asunnot.oikotie.fi/myytavat-asunnot/helsinki/15597485"
var str = UrlFetchApp.fetch(url).getContentText();
let r = /ce" content="(\d{6})">|hed" content="(.*)">/g,out=[];
let arr = [...str.matchAll(r)]; //[[ce" content="444000">, 444000, null], [hed" content="2020-03-28 11:06:22">, null, 2020-03-28 11:06:22]]
for(a of arr){
a.shift();
(a[0])?out.push(a[0]):out.push(a[1]);
}
Logger.log(out); //[444000, 2020-03-28 11:06:22]
}
This seems excessively cumbersome, any better options? I don't mind how it's done (regex or some other way, as long as I can consistently get the content of those two fields in the simplest way possible)
Final solution thanks to Wiktor Stribiżew's contribution:
function myFunction() {
var url = "https://asunnot.oikotie.fi/myytavat-asunnot/helsinki/15597485"
var str = UrlFetchApp.fetch(url).getContentText();
let r = /(?<=ce" content=")\d{6}(?=">)|(?<=hed" content=").*(?=">)/g;
let arr = str.match(r);
Logger.log(arr); //[444000, 2020-03-28 11:06:22]
}