Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

160
Vistas
How do you return the final redirect URL of a website using Google Apps Scripts

sorry if this is a simple question but I was wondering how I would be able to return the redirected URL of a webpage using google sheets.

Sample input webCode = SNSKS21KK

I've attached the code below:

function CHECKWEBSITE(webCode){ 
  if (webCode.map){
    return webCode.map(CHECKWEBSITE);
  } else {
    var url = 'https://www.torpedo7.co.nz/products/' + webCode;
    var redirectedUrl = ?;
    var options = {
      'muteHttpExceptions': true,
      'followRedirects': false
    };
    var response = UrlFetchApp.fetch(url, options);
    var status = response.getResponseCode();
    
    if (redirectedUrl.includes("discontinued") || status == 302) {
      return "Not Online"; 
    } else if (status == 200 || status == 301){ 
      return "Online";
    } else {
      return "Not imported";
    }
  }
} 

Expected redirect output = https://www.torpedo7.co.nz/products/SNSKS21KK/title/2022-e-s-force-fx-80-skis---m12-gw-f80-bindings

Thanks!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

In your situation, how about the following modification?

From:

var url = 'https://www.torpedo7.co.nz/products/' + webCode;
var redirectedUrl = ?;
var options = {
  'muteHttpExceptions': true,
  'followRedirects': false
};
var response = UrlFetchApp.fetch(url, options);
var status = response.getResponseCode();

To:

var url = 'https://www.torpedo7.co.nz/products/' + webCode;
var options = {
  'muteHttpExceptions': true,
  'followRedirects': false
};
var response = UrlFetchApp.fetch(url, options);
var redirectedUrl = response.getAllHeaders().Location;
var status = response.getResponseCode();
  • redirectedUrl is retrieved from Location of the response header.
  • When I tested the modified script using webCode = SNSKS21KK, redirectedUrl is https://www.torpedo7.co.nz/products/SNSKS21KK/title/2022-e-s-force-fx-80-skis---m12-gw-f80-bindings and Online was returned.

Reference:

  • fetch(url, params)
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda