Webサイトをクロールする
対象サイトとそのリンクされたページをクロールして包括的なデータを抽出します。詳細な使い方は、 CrawlAPIReferenceをご確認ください。
デフォルトでは、指定したURL階層に属さないサブリンクはクロールされません。たとえば、https://example.com/products/ をクロールしても、https://example.com/promotions/deal-567 の配下のページは取得されません。このようなリンクを含めるには、allowBackwardLinks パラメータを有効にしてください。
Scrapelessは、クロールリクエストの開始とそのステータスおよび結果の取得のためのエンドポイントを提供しています。デフォルトでは、クロールは非同期で処理されます。つまり、ジョブを開始してから、完了するまでそのステータスを確認します。ただし、SDKを使用する場合は、この一連の処理を自動で処理し、ジョブの完了後にデータを返すシンプルな関数を提供しています。
インストール
npm install @scrapeless-ai/sdk
pnpm add @scrapeless-ai/sdk
使用方法
import { ScrapingCrawl } from "@scrapeless-ai/sdk";
// Initialize the client
const client = new ScrapingCrawl({
apiKey: "your-api-key", // Get your API key from https://scrapeless.com
});
(async () => {
const result = await client.crawlUrl(
"https://example.com",
{
limit: 2,
scrapeOptions: {
formats: ["markdown", "html", "links"],
onlyMainContent: false,
timeout: 15000,
},
browserOptions: {
proxyCountry: "ANY",
sessionName: "Crawl",
sessionRecording: true,
sessionTTL: 900,
},
}
);
console.log(result);
})();
レスポンス
{
"success": true,
"status": "completed",
"completed": 2,
"total": 2,
"data": [
{
"url": "https://example.com",
"metadata": {
"title": "Example Page",
"description": "A sample webpage"
},
"markdown": "# Example Page\nThis is content...",
...
},
...
]
}
クロールされた各ページは、それぞれ completed または failed のステータスを持ち、個別のエラーフィールドを持つ可能性があるため、注意が必要です。
スキーマの全体像を確認するには、 APIReferenceを確認してください。
ブラウザ設定
スクレイピングジョブを実行するために使用されるセッションの設定を、新しいセッションの作成時に指定することもできます。これには、プロキシの使用などが含まれます。
利用可能なパラメータの完全なリストについては、 APIReference または ブラウザのパラメータを参照してください。
import { ScrapingCrawl } from "@scrapeless-ai/sdk";
// Initialize the client
const client = new ScrapingCrawl({
apiKey: "your-api-key", // Get your API key from https://scrapeless.com
});
(async () => {
const result = await client.crawlUrl(
"https://example.com",
{
limit: 2,
browserOptions: {
proxyCountry: "ANY",
sessionName: "Crawl",
sessionRecording: true,
sessionTTL: 900,
},
}
);
console.log(result);
})();
スクレイプ設定
レスポンス形式の指定、メインコンテンツのみの抽出の有効化、ページナビゲーションの最大タイムアウトの設定など、スクレイプジョブのためのオプションパラメータを指定することもできます。
import { ScrapingCrawl } from "@scrapeless-ai/sdk";
// Initialize the client
const client = new ScrapingCrawl({
apiKey: "your-api-key", // Get your API key from https://scrapeless.com
});
(async () => {
const result = await client.crawlUrl(
"https://example.com",
{
limit: 2,
scrapeOptions: {
formats: ["markdown", "html", "links"],
onlyMainContent: false,
timeout: 15000,
}
}
);
console.log(result);
})();
crawlエンドポイントの詳細なリファレンスについては、 APIReferenceを確認してください。