自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

直接把任意網(wǎng)站變?yōu)?API 接口?Firecrawl有點牛了!

開發(fā) 前端
Firecrawl 是一種 API 服務,它獲取 URL、對其進行抓取并將其轉(zhuǎn)換為干凈的 markdown 或結構化數(shù)據(jù)。我們會抓取所有可訪問的子頁面并為您提供每個子頁面的干凈數(shù)據(jù)。無需站點地圖。

Hello,大家好,我是 Sunday。

最近看到了一個爬蟲類框架:firecrawl 號稱 可以抓取任何網(wǎng)站并將其轉(zhuǎn)換為干凈的 markdown 或結構化數(shù)據(jù)。并且可以直接通過 Node 進行部署。

看這樣的描述有點厲害了,所以,咱們今天就來看看這個 firecrawl

01:什么是 firecrawl

firecrawl 是一種 API 服務,它獲取 URL、對其進行抓取并將其轉(zhuǎn)換為干凈的 markdown 或結構化數(shù)據(jù)。我們會抓取所有可訪問的子頁面并為您提供每個子頁面的干凈數(shù)據(jù)。無需站點地圖。

目前 Firecrawl 開源 3周 的時間,已經(jīng)有了 7.9K 的 star 數(shù),可以說是一個優(yōu)秀的項目了

圖片圖片

02:如何使用 firecrawl

想要使用 firecrawl ,那么首先需要獲取 API 秘鑰。秘鑰分為 收費 和 免費 兩種,大家如果不在商業(yè)項目中使用,通過 免費計劃 即可

圖片圖片

獲取秘鑰在這里注冊并獲?。篽ttps://www.firecrawl.dev/pricing

有了秘鑰之后,可以直接基于 Node 包創(chuàng)建項目即可:

  1. 安裝依賴包 npm install @mendable/firecrawl-js
  2. 將 API 密鑰設置為命名的環(huán)境變量FIRECRAWL_API_KEY或?qū)⑵渥鳛閰?shù)傳遞給FirecrawlApp類
  3. 如要抓取單個 URL ,可直接通過 scrapeUrl 方法
try {
  const url = "https://example.com";
  const scrapedData = await app.scrapeUrl(url);
  console.log(scrapedData);
} catch (error) {
  console.error("Error occurred while scraping:", error.message);
}
  1. 如要爬取網(wǎng)站信息,可以直接通過 crawlUrl 方法。該方法以起始 URL 和可選參數(shù)作為參數(shù)。該params參數(shù)允許您為抓取作業(yè)指定其他選項,例如要抓取的最大頁面數(shù)、允許的域和輸出格式。
const crawlUrl = "https://example.com";
const params = {
  crawlerOptions: {
    excludes: ["blog/"],
    includes: [], // leave empty for all pages
    limit: 1000,
  },
  pageOptions: {
    onlyMainContent: true,
  },
};
const waitUntilDone = true;
const timeout = 5;
const crawlResult = await app.crawlUrl(
  crawlUrl,
  params,
  waitUntilDone,
  timeout
);
  1. 可以通過 checkCrawlStatus 方法檢查爬取狀態(tài)
const status = await app.checkCrawlStatus(jobId);
console.log(status);
  1. 使用 LLM 可自動格式化所有數(shù)據(jù)
import FirecrawlApp from "@mendable/firecrawl-js";
import { z } from "zod";

const app = new FirecrawlApp({
  apiKey: "fc-YOUR_API_KEY",
});

// Define schema to extract contents into
const schema = z.object({
  top: z
    .array(
      z.object({
        title: z.string(),
        points: z.number(),
        by: z.string(),
        commentsURL: z.string(),
      })
    )
    .length(5)
    .describe("Top 5 stories on Hacker News"),
});

const scrapeResult = await app.scrapeUrl("https://news.ycombinator.com", {
  extractorOptions: { extractionSchema: schema },
});

console.log(scrapeResult.data["llm_extraction"]);
  1. 使用該 search 方法,您可以在搜索引擎中搜索查詢并獲取排名靠前的結果以及每個結果的頁面內(nèi)容。該方法將查詢作為參數(shù)并返回搜索結果。
const query = "what is mendable?";
const searchResults = await app.search(query, {
  pageOptions: {
    fetchPageContent: true, // 獲取每個搜索結果的頁面內(nèi)容
  },
});


責任編輯:武曉燕 來源: 程序員Sunday
相關推薦

2025-02-18 11:02:01

2022-07-26 07:05:50

PythonAPI語法

2023-02-12 15:47:33

TCP客戶端RST

2014-03-11 11:21:23

2021-08-26 10:29:47

工具Root框架

2024-08-26 09:36:06

2021-04-23 22:35:32

程序員工具網(wǎng)站

2011-03-04 14:39:32

Vsftpd啟動xinetd

2017-11-03 17:05:11

開源

2021-09-30 18:22:46

VSCode插件API

2015-12-09 14:51:57

2022-06-08 10:01:23

性能優(yōu)化慢查詢

2019-08-02 10:31:21

深度學習編程人工智能

2017-11-02 11:05:20

HTTP網(wǎng)站HTTPS網(wǎng)站免費

2023-06-26 10:37:02

2023-01-26 11:43:03

線程池CPUJava

2022-08-02 18:51:13

數(shù)據(jù)產(chǎn)品MySQL宕機

2021-01-19 05:27:44

HTTPSECDHE算法

2017-05-18 07:54:44

2010-12-17 13:01:55

點贊
收藏

51CTO技術棧公眾號