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

280
Views
How to handle empty <dt> values in Web-Scraping using JavaScript

I have a JavaScript code that scrapes data in a dl Description List. There are possible 7 dt values with respective dd values.

Only those of the 7 dt values and their dd values are shown on the website that have at least 1 dd value - thus, it can be 1 dt incl. dd is scraped or in another webpage 7

OK, I have a working Javascript code, that does the job!

const columns = [
  { text: 'Website', name: 'Website' },
  { text: 'Phone', name: 'Phone' },
  { text: 'Industry', name: 'Industry' },
  { text: 'Company size', name: 'Companysize' },
  { text: 'Headquarters', name: 'Headquarters' },
  { text: 'Founded', name: 'Founded' },
  { text: 'Specialties', name: 'Specialties' },
  { text: 'Employees', name: 'Employees' }  
]

const result = [];

const elements = document.querySelectorAll('dl dt');
elements.forEach((element) => {
  const regex = new RegExp(element.innerText, 'i');
  const findColumn = columns.find((column) => regex.test(column.text));

  if (!findColumn) return;

  const columnValue = element.nextElementSibling.innerText;
  result.push({ [findColumn.name]: columnValue });
});

Problem

I want to save the scraping results in an MS Excel table that has 7 columns BUT --> The result of the scraping can have1 up to 7 columns

Because of that, I can't simply append the results, row by row - I have to do it manually. Copying the right value in the right column for it.

I would need a code that can do the following:

The values of the 7 dt elements are the header of the 7 columns The code always results in 7 values

  1. If the ddis a real value and accordingly scraped by the code above, then it is put in the correct column
  2. If there is no dt element, then the string "n/a" should be put under the respective column.

This way, the results are stored in a consistent Excel table with always the correct values in the correct column.

I cannot find any specific info or material or sample code to write JavaScript code to solve this task! I think, a JavaScript expert is needed to write that code.

Thank you for helping me out to understand JavaScript better and to learn how to write JS code.

P.S.: The website scraping from: LinkedIn companies

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!