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
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