feat(wip): init be scraping

This commit is contained in:
karishmas6
2024-04-12 12:12:55 +05:30
parent 83a7942300
commit fa6ff65a4c

25
scraper/src/main.js Normal file
View File

@@ -0,0 +1,25 @@
// import Fastify from 'fastify'
// import { PlaywrightCrawler } from 'crawlee';
// const fastify = Fastify();
const fastify = require('fastify')();
const scraper = require('./scraper');
fastify.post('/scrape', async (request, reply) => {
const { url, selections } = request.body;
try {
const data = await scraper.scrape(url, selections);
console.log('Scraped data:', data);
reply.send(data);
} catch (error) {
console.error('Error scraping:', error);
reply.status(500).send({ error: 'Failed to scrape data' });
}
});
fastify.listen(3000, (err, address) => {
if (err) throw err;
console.log(`Server is now listening on ${address}`);
});