I'm not too familiar with advanced javascript and looking for some guidance. I'm looking to store webpage content into DB using puppeteer-cluster Here's a starting example:
const { Cluster } = require('puppeteer-cluster');
(async () => {
const cluster = await Cluster.launch({
concurrency: Cluster.CONCURRENCY_CONTEXT,
maxConcurrency: 2,
});
await cluster.task(async ({ page, data: url }) => {
await page.goto(url);
const screen = await page.content();
// Store content, do something else
});
cluster.queue('http://www.google.com/');
cluster.queue('http://www.wikipedia.org/');
// many more pages
await cluster.idle();
await cluster.close();
})();
Looks like I may have to use pg addon to connect to db. What would be the recommended approach to this?
Here's my table:
+----+-----------------------------------------------------+---------+
| id | url | content |
+----+-----------------------------------------------------+---------+
| 1 | https://www.npmjs.com/package/pg | |
+----+-----------------------------------------------------+---------+
| 2 | https://github.com/thomasdondorf/puppeteer-cluster/ | |
+----+-----------------------------------------------------+---------+
I believe I'd have to pull data into an array (id & url), and after each time content is received, store it into the DB (by id & content).