feat(wip): init be scraping
This commit is contained in:
25
scraper/src/main.js
Normal file
25
scraper/src/main.js
Normal 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}`);
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user