Selenium MCP Server
MCP server for crawling and extracting data from web pages using Selenium with CSS/XPath selectors. Supports 17 tools including smart extraction, pagination, infinite scroll, and screenshots.
README
🕷️ Selenium MCP Server
MCP server (stdio) sử dụng Selenium để crawl và trích xuất dữ liệu từ web pages bằng CSS/XPath selectors.
✨ Tính Năng
MCP Tools (17 tools)
| Tool | Mô Tả |
|---|---|
extract |
Trích xuất dữ liệu cơ bản với CSS/XPath selectors |
analyze_page |
Phân tích cấu trúc trang trước khi extract |
smart_extract |
Tự động detect loại trang và extract (products, article, all) |
crawl_all_pages |
Crawl nhiều trang với pagination |
crawl_infinite_scroll |
Xử lý lazy loading/infinite scroll |
discover_site |
Khám phá sitemap, categories, navigation |
crawl_category_list |
Crawl nhiều category URLs |
deep_crawl |
Crawl listing + chi tiết từng sản phẩm |
extract_product_details |
Extract chi tiết từ danh sách URLs |
export_results |
Xuất CSV/JSON |
take_screenshot |
Chụp full-page screenshot |
take_element_screenshot |
Chụp screenshot của element cụ thể |
manage_cookies |
Get/Set/Clear browser cookies |
login_and_extract |
Đăng nhập và extract từ trang protected |
execute_javascript |
Thực thi JavaScript tùy chỉnh |
get_page_metrics |
Lấy performance metrics của trang |
REST API Endpoints
Server cũng cung cấp REST API đầy đủ qua FastAPI:
POST /extract- Basic extractionPOST /smart-extract- Smart extractionPOST /analyze- Analyze pagePOST /crawl/pages- Crawl with paginationPOST /crawl/infinite-scroll- Handle infinite scrollPOST /crawl/categories- Crawl categoriesPOST /crawl/deep- Deep crawlPOST /discover- Discover sitePOST /products/details- Product detailsPOST /screenshot- Capture screenshotPOST /export- Export dataGET /jobs- List jobsGET /outputs- List output files
🚀 Cài Đặt
# Clone repo
git clone https://github.com/Tai-DT/mcp-crawler.git
cd mcp-crawler
# Tạo virtual environment
python3 -m venv venv
source venv/bin/activate # Linux/Mac
# hoặc: venv\Scripts\activate # Windows
# Cài đặt dependencies
pip install -r requirements.txt
📦 Chạy Server
MCP Server (cho AI clients)
# Stdio mode (mặc định, cho MCP clients)
python3 selenium_mcp_server.py
# HTTP mode (cho debugging)
python3 selenium_mcp_server.py --transport streamable-http --host 127.0.0.1 --port 8000
REST API Server
python3 server_api.py
# API sẽ chạy tại http://localhost:8000
Docker
docker-compose up -d
# API: http://localhost:8000
⚙️ Cấu Hình MCP Client
VS Code (mcp.json)
{
"servers": {
"local/selenium-crawler": {
"type": "stdio",
"command": "/path/to/mcp-crawler/venv/bin/python",
"args": ["/path/to/mcp-crawler/selenium_mcp_server.py"],
"env": {}
}
}
}
Claude Desktop
{
"mcpServers": {
"selenium-crawler": {
"command": "python3",
"args": ["/path/to/mcp-crawler/selenium_mcp_server.py"]
}
}
}
📖 Ví Dụ Sử Dụng
Basic Extract
{
"url": "https://example.com",
"fields": {
"title": "css:h1",
"description": "css:p",
"links": {"selector": "css:a", "attribute": "href", "multiple": true}
}
}
Smart Extract Products
{
"url": "https://shop.example.com/category",
"extract_type": "products",
"limit": 50,
"normalize_prices": true
}
Deep Crawl
{
"url": "https://shop.example.com/products",
"follow_links": "products",
"max_links": 20,
"normalize_prices": true
}
Screenshot
{
"url": "https://example.com",
"full_page": true,
"width": 1920,
"height": 1080
}
Login and Extract
{
"login_url": "https://example.com/login",
"target_url": "https://example.com/dashboard",
"username_selector": "css:#email",
"password_selector": "css:#password",
"submit_selector": "css:button[type='submit']",
"username": "user@example.com",
"password": "password123",
"fields": {
"welcome_message": "css:.welcome",
"account_name": "css:.account-name"
}
}
🔄 Retry & Error Handling
Server có built-in retry với exponential backoff:
- Max Retries: 3 lần
- Initial Delay: 1 giây
- Backoff Factor: 2x
- Rate Limiting: 30 requests/phút
📁 Cấu Trúc Dự Án
mcp-crawler/
├── selenium_mcp_server.py # MCP Server chính (17 tools)
├── server_api.py # REST API (FastAPI)
├── crawler_engine.py # Crawler engine core
├── extraction_utils.py # Tiện ích xử lý dữ liệu
├── config.py # Configuration management
├── retry_handler.py # Retry & rate limiting
├── job_manager.py # Job tracking & persistence
├── requirements.txt # Python dependencies
├── Dockerfile # Docker image
├── docker-compose.yml # Docker Compose
├── outputs/ # Extracted data
│ └── screenshots/ # Captured screenshots
├── jobs/ # Job history
└── scripts/ # Test scripts
🧪 Testing
# Test crawler engine
python3 test_mcp.py
# Smoke test MCP server
python3 scripts/smoke_test_stdio.py
📝 License
MIT
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.