Help

Populate page title of a url

Topic Labels: Scripting extentions
865 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Ben_Crouch
6 - Interface Innovator
6 - Interface Innovator

I’m not sure if this would be a script, but I have a table full of URLs and I want to query the ‘page title’ for that URL and return it to populate in another field ‘Page title’. Does anyone know if this is possible and if so what script I should run?

Thanks

1 Reply 1
Melissa_Mcewen
5 - Automation Enthusiast
5 - Automation Enthusiast

For anyone else searching, here is some code that gets the title from a webpage to populate a title field

// Define the table names

const urlTableName = "URLs";


let urlTable = base.getTable(urlTableName);

// Prompt the user to select the current link record
let record = await input.recordAsync('Pick a link record', urlTable);


// Check if a record was selected
if (!record) {
  output.text("No record selected. Please select a record to run the script.");
} else {
  
  const url = record.getCellValue('URL');

  const response = await remoteFetchAsync(url + "/");
  const text = await response.text();

  const title = text.match(/<title>(.*?)<\/title>/)[1];

   await urlTable.updateRecordAsync(record.id, {
      'Title': title
    });
  console.log(`Updated record ${record.id} with title: ${title}`);
}