The issue is because when you invoke
text() on a jQuery object targeting multiple elements jQuery will automatically concatenate their values, hence no spaces between values.
To better way to approach this would be to use
map() to create an array of the values. Then you can
join() this array to form a string in whatever format you need. Here’s an example which separates the values by a comma:
let matches = $('span.AvvenimentoDescription-rieyuj-0').map((i, el) => el.textContent.trim()).get();
let output = matches.join(', ');
I was working on web scraping with puppeteer on this Italian betting site, I want to select the div which contains the two teams name, making part of the game. So I did this:
let matches = $('span.AvvenimentoDescription-rieyuj-0').text();
and it returned me this:
'Bologna - BresciaCagliari - ParmaSassuolo - RomaJuventus - FiorentinaAtalanta - GenoaLazio - SpalMilan - Hellas VeronaLecce - TorinoUdinese - InterSampdoria - Napoli'
As you can see the matches are next to each other:
'Bologna - BresciaCagliari - Parma...'
I want it to be:
'Bologna - Brescia Cagliari - Parma...'
or even better
`'Bologna - Brescia,Cagliari - Parma...`
So, is there a way to add a space or a comma every times that $() selects something?