Skip to main content
Open In ColabOpen on GitHub

Scrapingbee GoogleSearchTool

Use this tool to search on Google for normal search results as well as news, maps, and images.

Overviewโ€‹

Integration detailsโ€‹

ClassPackageSerializableJS supportPackage latest
GoogleSearchToollangchain-scrapingbeeโœ…โŒPyPI - Version

Setupโ€‹

pip install -U langchain-scrapingbee

Credentialsโ€‹

You should configure credentials by setting the following environment variables:

  • SCRAPINGBEE_API_KEY
import getpass
import os

# if not os.environ.get("SCRAPINGBEE_API_KEY"):
# os.environ["SCRAPINGBEE_API_KEY"] = getpass.getpass("SCRAPINGBEE API key:\n")

Instantiationโ€‹

All of the ScrapingBeee tools only require the API Key during instantiation. If not set up in environment vairable, you can provide it directly here.

Here we show how to instantiate an instance of the Scrapingbee tools:

from langchain_scrapingbee import GoogleSearchTool

search_tool = GoogleSearchTool(api_key=os.environ.get("SCRAPINGBEE_API_KEY"))

Invocationโ€‹

Invoke directly with argsโ€‹

This tool accepts search (string) and params (dictionary) as argument. The search argument is necessary, and the params argument is optional. You can use params argument to customise the request. For example, to get news results, you can use the following as params:

{'search_type': 'news'}

For a complete list of acceptable parameters, please visit the Google Search API documentation.

search_result = search_tool.invoke({"search": "What is LangChain?"})

Use within an agentโ€‹

import os
from langchain_scrapingbee import GoogleSearchTool
from langchain_google_genai import ChatGoogleGenerativeAI
from langgraph.prebuilt import create_react_agent

if not os.environ.get("GOOGLE_API_KEY") or not os.environ.get("SCRAPINGBEE_API_KEY"):
raise ValueError(
"Google and ScrapingBee API keys must be set in environment variables."
)

llm = ChatGoogleGenerativeAI(temperature=0, model="gemini-2.5-flash")
scrapingbee_api_key = os.environ.get("SCRAPINGBEE_API_KEY")

search_tool = GoogleSearchTool(api_key=os.environ.get("SCRAPINGBEE_API_KEY"))

agent = create_react_agent(llm, [search_tool])

user_input = "Fetch 5 news about Tesla that includes: headline in 5 words or less, summary in 30 words or less, link, and date"

# Stream the agent's output step-by-step
for step in agent.stream(
{"messages": user_input},
stream_mode="values",
):
step["messages"][-1].pretty_print()
API Reference:create_react_agent

API referenceโ€‹

For detailed documentation of all Google Search API features and configurations head to the API reference.