for(var x in urls){
var response = UrlFetchApp.fetch(urls[x],urlFetchOptions);
var code = response.getContentText();
for(var y = 0; y < messagesToCheckFor.length; y++){
var message = messagesToCheckFor[y];
if(code.indexOf(message) !== -1){
bad_urls.push(urls[x]);
break;
}
}
}`
This code in a Google Ads script checks through all URLs for a piece of HTML, and if found, pushes that URL to an array (bad_urls). However I'd like to amend it so that it instead counts the number of occurrences of the piece of HTML and then adds each URL and the total count to an array so that I can record their values in a google sheet
I think I need something like the below to use regex to count successive matches but I'm not sure how to add the count to a variable and then push both url and count to their own array. Thanks
var re = /dpb-product-link svelte-1yex87k/g;
var outofStockMatch = [];
count = 0;
while (re.exec(code)) {
outofStockMatch = ++count;