Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

188
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!