I'm completely new to Google Apps Script and JavaScript.
I just wanted to:
title and num count.title into column B and the num count into column C.Here's my code:
function getHtml()
{
var sheet = SpreadsheetApp.getActiveSheet();
var data = sheet.getDataRange().getValues();
var url_range = sheet.getRange('A1:A').getValue();
var response = UrlFetchApp.fetch(url);
var content = response.getContentText("UTF-8");
var title = new Array();
var num_count = new Array();
for (var i = 1; i < data.length; i++) {
title = content.match(/<title>(.*?)<\/title>/);
num_count = content.match(/<span class="num_count">(.*?)<\/span>/);
}
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet1 = ss.getSheetByName("sheet1");
for (var i = 1; i < data.length; i++) {
sheet1.getRange(i,2).setValue(title[i]);
sheet1.getRange(i,3).setValue(num_count[i]);
}
}
But I only get the below result:

Please tell me what I should improve.
Assuming that your scraping works I think this is pretty close to what you require.
function getHtml()
{
var ss=SpreadsheetApp.getActive();
var sheet=ss.getActiveSheet();
var range=sheet.getRange(1,1,sheet.getLastRow(),3);
var data=range.getValues();
for(var i=0;i<data.length;i++){
var response = UrlFetchApp.fetch(data[i][0]);
var content = response.getContentText("UTF-8");
data[i][1]=content.match(/<title>(.*?)<\/title>/);
data[i][2]=content.match(/<span class="num_count">(.*?)<\/span>/);
}
rg.setValues(data);
}
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