After collecting data from multiple sources, the output I obtained is as follows:
"addressId":"132234","businessEntryCount":2026},{"district":"Nordend-West","districtSlug":"frankfurt-am-main-nordend-west","addressId":"132232","businessEntryCount":1925}],"generated":"2022-01-23 19:35:43.469","grisuLocation":null,"district":null,"geo":null};
kt.Data.SearchResult.distanceLocation = "Frankfurt am Main";
kt.Data.SearchResult.distanceStreetnumber = "";
kt.Service.citySlug = 'frankfurt';
kt.Data.what = 'Handwerker';
kt.Data.where = 'Frankfurt am Main';
kt.Data.trade = 'Maler';
{"@context":"http:\/\/schema.org","@type":"SearchResultsPage","mainEntity":{"@type":"ItemList","itemListElement":[{"@type":"ListItem","item":{"@type":"LocalBusiness","name":"Dachdecker Olaf Pocklitz","url":"http:\/\/www.test.de","email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5d29382e291d2970323331343338733938">[email protected]</a>","address":{"@type":"PostalAddress",...
The above information represents my collected data, and my goal is to extract all email addresses in order to store them in a file. In this instance, the email address would be [email protected]. If there are more than one email address, each additional email should be on a new line. I am facing difficulties in properly filtering out the email addresses and then saving them individually by line. Although I have managed to save the data, I am unsure of how to isolate just the email addresses:
console.log('received data: ' + data)
fs.writeFileSync('./results/test.json', data)
EDIT:
This is the code I have developed thus far:
var matches = data.match(/\"mainEntity":{"(.*?)\"}/);
var preResult = [matches]
//.itemListElement[0].item.email
console.log('received data: ' + preResult)
fs.writeFileSync('./results/test.json', preResult)
However, despite my efforts, I am unable to access the email within the result:
"mainEntity":{"@type":"ItemList","itemListElement":[{"@type":"ListItem","item":{"@type":"LocalBusiness","name":"Dachdecker Olaf test","url":"http:\/\/www.test.de","email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cfbbaabcbb8fbbe2a0a1a3a6a1aae1abaa">[email protected]</a>","address":{....