Skip to main content
Glama

Web Scraper MCP Server

Web Scraper MCP Server

基于 Model Context Protocol (MCP) 的 TypeScript 网页爬取服务器,内置多种常用爬取与命令工具。

功能特性

  • 🚀 多种导出格式: 支持将爬取内容导出为 Markdown、Text、HTML ��� JSON 格式
  • 🎭 Puppeteer 无头浏览器: 解决未实现静态化的 SPA 单页应用渲染问题
  • 📋 规则集支持: 支持设置规则集,实现抓取网页的特定部分内容
  • 🔧 自定义域名 Headers: 支持设置自定义域名 Headers,绕过网站登录限制
  • 📦 批量爬取: 支持同时爬取多个 URL
  • 🎯 智能内容提取: 自动识别和提取网页主要内容

安装

# 克隆项目 git clone <repository-url> cd web-scraper-mcp # 安装依赖 npm install # 构建项目 npm run build

使用方法

启动服务器

npm start

可用工具

1. scrape_url - 爬取单个网页
{ "name": "scrape_url", "arguments": { "url": "https://example.com", "format": "markdown", "usePuppeteer": false, "ruleSet": "blog", "customHeaders": { "Authorization": "Bearer token" } } }

参数说明:

  • url (必需): 要爬取的网页 URL
  • format (可选): 导出格式,支持 markdowntexthtmljson,默认为 markdown
  • usePuppeteer (可选): 是否使用 Puppeteer 无头浏览器,默认为 false
  • ruleSet (可选): 规则集名称,用于提取特定内容
  • customHeaders (可选): 自定义请求头
2. create_rule_set - 创建内容提取规则集
{ "name": "create_rule_set", "arguments": { "name": "my_blog_rule", "rules": { "title": "h1, .post-title", "content": ".post-content, article", "links": ".post-content a", "images": ".post-content img", "exclude": ["nav", "footer", ".sidebar"] } } }

参数说明:

  • name (必需): 规则集名称
  • rules (必需): 提取规则配置
    • title: 标题选择器
    • content: 内容选择器
    • links: 链接选择器
    • images: 图片选择器
    • exclude: 要排除的选择器列表
3. set_domain_headers - 设置域名请求头
{ "name": "set_domain_headers", "arguments": { "domain": "example.com", "headers": { "Authorization": "Bearer your-token", "X-Custom-Header": "custom-value" } } }
4. batch_scrape - 批量爬取
{ "name": "batch_scrape", "arguments": { "urls": [ "https://example1.com", "https://example2.com", "https://example3.com" ], "format": "markdown", "usePuppeteer": false, "ruleSet": "blog" } }

预定义规则集

系统内置了以下规则集:

  • blog: 适用于大多数博客文章页面
  • news: 适用于新闻网站文章
  • product: 适用于电商产品页面
  • documentation: 适用于技术文档页面
  • forum: 适用于论坛帖子页面

导出格式

Markdown

将网页内容转换为 Markdown 格式,包含标题、内容、链接和图片。

Text

纯文本格式,去除所有 HTML 标签。

HTML

清理后的 HTML 格式,移除脚本和样式。

JSON

完整的结构化数据,包含所有提取的信息。

开发

项目结构

src/ ├── index.ts # 主服务器文件 ├── scraper/ │ └── webScraper.ts # 网页爬取器 ├── export/ │ └── exportManager.ts # 导出管理器 ├── rules/ │ └── ruleEngine.ts # 规则引擎 ├── headers/ │ └── headerManager.ts # 请求头管理器 └── utils/ └── logger.ts # 日志工具

开发模式

# 监听文件变化并自动重新构建 npm run dev

测试

npm test

配置

环境变量

  • LOG_LEVEL: 日志级别 (debug, info, warn, error)
  • PUPPETEER_TIMEOUT: Puppeteer 超时时间(毫秒)
  • REQUEST_TIMEOUT: HTTP 请求超时时间(毫秒)

自定义配置

可以通过修改源代码来自定义:

  1. 默认请求头: 编辑 src/headers/headerManager.ts
  2. 预定义规则集: 编辑 src/rules/ruleEngine.ts
  3. 导出格式: 编辑 src/export/exportManager.ts

常见问题

Q: 为什么某些网站爬取失败?

A: 可能是因为网站有反爬虫机制。尝试:

  1. 使用 usePuppeteer: true 启用无头浏览器
  2. 设置合适的自定义请求头
  3. 使用预定义的反检测请求头

Q: 如何处理需要登录的网站?

A: 使用 set_domain_headers 工具设置包含认证信息的请求头,如 Cookie 或 Authorization。

Q: SPA 应用内容为空怎么办?

A: 设置 usePuppeteer: true 使用 Puppeteer 渲染动态内容。

许可证

MIT License

贡献

欢迎提交 Issue 和 Pull Request!

Deploy Server
A
security – no known vulnerabilities
A
license - permissive license
A
quality - confirmed to work

hybrid server

The server is able to function both locally and remotely, depending on the configuration or use case.

A TypeScript-based web scraping server built on the Model Context Protocol that offers multiple export formats, content extraction rules, and support for both static and dynamic (SPA) websites.

  1. 功能特性
    1. 安装
      1. 使用方法
        1. 启动服务器
        2. 可用工具
        3. 预定义规则集
        4. 导出格式
      2. 开发
        1. 项目结构
        2. 开发模式
        3. 测试
      3. 配置
        1. 环境变量
        2. 自定义配置
      4. 常见问题
        1. Q: 为什么某些网站爬取失败?
        2. Q: 如何处理需要登录的网站?
        3. Q: SPA 应用内容为空怎么办?
      5. 许可证
        1. 贡献

          Related MCP Servers

          • A
            security
            A
            license
            A
            quality
            A TypeScript-based MCP server utilizing the UseScraper API to provide web scraping capabilities, allowing users to extract content from webpages in various formats.
            Last updated -
            1
            2
            JavaScript
            MIT License
            • Apple
          • A
            security
            A
            license
            A
            quality
            A production-ready Model Context Protocol server that enables language models to leverage AI-powered web scraping capabilities, offering tools for transforming webpages to markdown, extracting structured data, and executing AI-powered web searches.
            Last updated -
            5
            36
            Python
            MIT License
            • Apple
          • -
            security
            A
            license
            -
            quality
            A Model Context Protocol server that allows LLMs to interact with web content through standardized tools, currently supporting web scraping functionality.
            Last updated -
            Python
            MIT License
            • Linux
            • Apple
          • A
            security
            A
            license
            A
            quality
            A Model Context Protocol server enabling AI assistants to scrape web content with high accuracy and flexibility, supporting multiple scraping modes and content formatting options.
            Last updated -
            4
            616
            2
            TypeScript
            MIT License
            • Linux
            • Apple

          View all related MCP servers

          MCP directory API

          We provide all the information about MCP servers via our MCP API.

          curl -X GET 'https://glama.ai/api/mcp/v1/servers/naku111/mcpServer'

          If you have feedback or need assistance with the MCP directory API, please join our Discord server