2024-08-08 22:41:13 +08:00
|
|
|
import FirecrawlApp from './firecrawl/src/index'; //'@mendable/firecrawl-js';
|
2024-04-16 22:38:22 +08:00
|
|
|
|
2024-05-09 21:36:56 +08:00
|
|
|
const app = new FirecrawlApp({apiKey: "fc-YOUR_API_KEY"});
|
2024-04-16 22:38:22 +08:00
|
|
|
|
2024-05-09 21:36:56 +08:00
|
|
|
// Scrape a website:
|
|
|
|
const scrapeResult = await app.scrapeUrl('firecrawl.dev');
|
2024-08-08 22:41:13 +08:00
|
|
|
|
|
|
|
if (scrapeResult.data) {
|
|
|
|
console.log(scrapeResult.data.markdown)
|
|
|
|
}
|
2024-05-09 21:36:56 +08:00
|
|
|
|
|
|
|
// Crawl a website:
|
2024-08-08 22:41:13 +08:00
|
|
|
const crawlResult = await app.crawlUrl('mendable.ai', {crawlerOptions: {excludes: ['blog/*'], limit: 5}}, false);
|
2024-04-16 22:38:22 +08:00
|
|
|
console.log(crawlResult)
|
|
|
|
|
|
|
|
const jobId = await crawlResult['jobId'];
|
|
|
|
console.log(jobId);
|
|
|
|
|
|
|
|
let job;
|
|
|
|
while (true) {
|
|
|
|
job = await app.checkCrawlStatus(jobId);
|
2024-08-08 22:41:13 +08:00
|
|
|
if (job.status === 'completed') {
|
2024-04-16 22:38:22 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
await new Promise(resolve => setTimeout(resolve, 1000)); // wait 1 second
|
|
|
|
}
|
|
|
|
|
2024-08-08 22:41:13 +08:00
|
|
|
if (job.data) {
|
|
|
|
console.log(job.data[0].markdown);
|
2024-05-09 21:36:56 +08:00
|
|
|
}
|
|
|
|
|
2024-08-08 22:41:13 +08:00
|
|
|
const mapResult = await app.map('https://firecrawl.dev');
|
|
|
|
console.log(mapResult)
|