I am currently working on developing an API using express, puppeteer-cluster, and cheerio to extract anchor elements containing specific words that can be used as query parameters. My aim is to utilize puppeteer to capture dynamically generated elements as well. However, I am facing an issue where I am receiving an empty array as the output displayed on the browser.
Despite dedicating the past 2 days to mastering this library, I have made no significant progress. Any assistance or guidance would be greatly appreciated.
Update: I have updated all my functions to include async operations, which have enabled them to run successfully. However, the end result still remains empty :(
Update 2: Upon thorough logging and debugging, I have identified that the data.name is being passed as a Promise to the cheerio function. This appears to be the root cause of the issue, although I am uncertain about how to resolve it at this point.
Update 3: One of the key challenges I encountered was the mishandling of the page content (HTML code) being passed to the cheerio function. Despite the content being empty in the browser response, an error is displayed in the console:
Error handling response: TypeError: Cannot read properties of undefined (reading 'innerText').
This leads me to believe that the response is not formatted as JSON. Could it be that res.json()
is not the correct method for formatting?
Here is a snippet of my code:
app.js
[code snippet for app.js]
cluster.js
[code snippet for cluster.js]
Despite not encountering any errors, I am presented with an empty output on the screen. Can anyone identify where I may be going wrong with this implementation? :(