docs/en/tools/web-scraping/serperscrapewebsitetool.mdx
SerperScrapeWebsiteToolThis tool is designed to scrape website content and extract clean, readable text from any website URL. It utilizes the serper.dev scraping API to fetch and process web pages, optionally including markdown formatting for better structure and readability.
To effectively use the SerperScrapeWebsiteTool, follow these steps:
crewai[tools] package is installed in your Python environment.serper.dev API key by registering for an account at serper.dev.SERPER_API_KEY to facilitate its use by the tool.To incorporate this tool into your project, follow the installation instructions below:
pip install 'crewai[tools]'
The following example demonstrates how to initialize the tool and scrape a website:
from crewai_tools import SerperScrapeWebsiteTool
# Initialize the tool for website scraping capabilities
tool = SerperScrapeWebsiteTool()
# Scrape a website with markdown formatting
result = tool.run(url="https://example.com", include_markdown=True)
The SerperScrapeWebsiteTool accepts the following arguments:
True.Here is an example demonstrating how to use the tool with different parameters:
from crewai_tools import SerperScrapeWebsiteTool
tool = SerperScrapeWebsiteTool()
# Scrape with markdown formatting (default)
markdown_result = tool.run(
url="https://docs.crewai.com",
include_markdown=True
)
# Scrape without markdown formatting for plain text
plain_result = tool.run(
url="https://docs.crewai.com",
include_markdown=False
)
print("Markdown formatted content:")
print(markdown_result)
print("\nPlain text content:")
print(plain_result)
The SerperScrapeWebsiteTool is particularly useful for:
The tool includes comprehensive error handling for:
SERPER_API_KEY in environment variables, never hardcode it in your source code