Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

293
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda