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

189
Vistas
access multiple pages with fetch, retrieve elements from each accessed page with querySelector, and make an array of the retrieved elements

I will use the StackOverflow page you are looking at now as an example.

Access each question link in the sidebar's“Related”by fetch Get the element of the Related page (in the example, the title of the page) with querySelector To make an array of the retrieved elements

The code written is as follows

Please paste it into the console on this page so you can see what it says.

I am unable to store it in an array and would appreciate your guidance.

let relatedPageURL = document.querySelectorAll(".sidebar-related .js-gps-track"); 
let relatedPageURLarray = []; 
let relatedPageHTMLtitleArray = []; 
for (let i = 0; i < relatedPageURL.length; i++) {
  relatedPageURLarray[i] = relatedPageURL[i].getAttribute("href"); 
  fetch(relatedPageURLarray[i]) 
    .then((response) => response.text())
    .then((text) => {
      let DOMtext = new DOMParser();
      let relatedPageHTML = DOMtext.parseFromString(text, "text/html");
      let relatedPageHTMLtitle = relatedPageHTML.querySelector("#question-header"); 
      relatedPageHTMLtitleArray[i] = relatedPageHTMLtitle; 
      console.log(relatedPageHTMLtitleArray);
    });
  }

  //result []

  //Expected Results [div#question-header.d-flex.sm:fd-column, div#question-header.d-flex.sm:fd-column, div#question-header.d-flex.sm:fd-column, div#question-header.d-flex.sm:fd-column, div#question-header.d-flex.sm:fd-column, div#question-header.d-flex.sm:fd-column, div#question-header.d-flex.sm:fd-column, div#question-header.d-flex.sm:fd-column, div#question-header.d-flex.sm:fd-column, div#question-header.d-flex.sm:fd-column]

about 4 years ago · Juan Pablo Isaza
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