0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【自動スクレイピング】Gemini APIがURLを渡すだけでスクレイピングしてくれるようになりました

0
Last updated at Posted at 2025-08-21

2025/08/19から、Gemini APIにURLを渡すと、Webページを詳細にスクレイピングしてくれるようになりました!

URLを指定するだけでサイト内の

  • PDF

  • 画像

  • テキスト

といった全てをコンテキストに出来ます。

私も試しにスクレイピングしてみましたが、他のAIよりかなり良さげでした(・∀・)

追加のツール費用なしで利用可能で、モデルが処理したトークン分のみ料金が発生します。超お得ですね。

使用方法

以下のようにAPIを叩くと可能です。

import { GoogleGenAI } from "@google/genai";

const ai = new GoogleGenAI({});

async function main() {
  const response = await ai.models.generateContent({
    model: "gemini-2.5-flash",
    contents: [
        "URLの内容について分析してください:https://www.hogefuga.com",
    ],
    config: {
      tools: [{urlContext: {}}],
    },
  });
  console.log(response.text);

  // 検証のために、メタデータを確認することで、モデルが取得したURLを確認できます
  console.log(response.candidates[0].urlContextMetadata


await main();

また、Google AI Studioの「URL context」をONにして使うこともできます。

画像

注意

現在はGemini 2.5 flashでのみ対応しています。

参照

公式ドキュメント


これからもQiitaで発信していくので、気になったらぜひいいね・フォローお願いします!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?