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

170
Views
querySelectorAll() returns list of empty nodes when used with jsdom

I am trying to scrape some information from wikipedia pages with my Node.js app, using jsdom. Here is an example of what I'm doing:

jsdom.env({
    url: "https://en.wikipedia.org/wiki/Bill_Gates",
    features: {
        FetchExternalResources: ['script'],
        ProcessExternalResources: ['script'],
        SkipExternalResources: false,
    },
    done: function (err, window) {
        if (err) {
            console.log("Error: ", err)
            return;
        }

        var paras = window.document.querySelectorAll('p');
        console.log("Paras: ", paras)
    }
});

The weird thing is that querySelectorAll('p') returns a NodeList of empty elements:

Paras:  NodeList {
  '0': HTMLParagraphElement {},
  '1': HTMLParagraphElement {},
  '2': HTMLParagraphElement {},
  '3': HTMLParagraphElement {},
  '4': HTMLParagraphElement {},
  '5': HTMLParagraphElement {},
  '6': HTMLParagraphElement {},
  '7': HTMLParagraphElement {},
  ...
  62': HTMLParagraphElement {} }

Any idea on what could be the problem? Thanks!

EDIT:

I got the same result when replacing window.document.querySelectorAll('p') with window.document.getElementsByTagName('p')

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The elements are not empty it just won't show you the result in a console log. You have to access data on them (textContent for it for example)

Try this:

Array.prototype.slice.call(dom.window.document.getElementsByTagName("p")).map(p => {
    console.log(p.textContent);
}
over 4 years ago · Santiago Trujillo Report
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!