Facebook Marketplace数据采集服务

一个基于FastMCP和Playwright的无头浏览器自动化工具,用于采集Facebook Marketplace的列表数据,支持按日期和位置筛选,并返回结构化数据。

  • by fisheyes
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 fisheyes/mcp-facebook-market-place

使用说明

Facebook市场MCP服务器

一个MCP(模型上下文协议)服务器,用于抓取脸书市场列表。采用FastMCP和Playwright构建,实现无头浏览器自动化。

特性

  • 搜索Facebook Marketplace列表
  • 按日期筛选(最近N天)
  • 按位置筛选
  • 返回结构化数据:标题、价格、位置、URL和图像
  • 与AWS Bedrock AgentCore运行时兼容
  • 用于云部署的流式HTTP传输

安装

# Clone the repository
git clone <repo-url>
cd facebook_market_place

# Install dependencies with uv
uv sync

# Install Playwright browser
uv run playwright install chromium

用法

作为MCP服务器(与AWS AgentCore兼容)

uv run python server.py

服务器启动于 http://0.0.0.0:8000/mcp 通过流式HTTP传输。

作为CLI工具

# Basic search
uv run python scraper.py "brewing fermenter"

# Filter to last 7 days
uv run python scraper.py "iphone 15" --days 7

# Output as JSON
uv run python scraper.py "laptop" --json

# Different location
uv run python scraper.py "bike" --location 123456789

# Debug mode (saves screenshot)
uv run python scraper.py "test" --debug

MCP工具

search_marketplace

在Facebook Marketplace上搜索列表。

参数:

名称 类型 必填 描述
query string 是 搜索词(例如“酿造发酵罐”)
days integer 否 仅显示最近N天(1、7、30)的列表
location_id string 否 Facebook位置ID(默认值: 108339199186201 英国)

退货:

[
  {
    "listing_id": "1383886916015812",
    "title": "33L Bucket Brewing Fermenter",
    "price": "£10",
    "location": "London",
    "url": "https://www.facebook.com/marketplace/item/1383886916015812",
    "image_url": "https://..."
  }
]

get_listing_details

获取特定列表的完整详细信息,包括描述和条件。

参数:

名称 类型 必填 描述
listing_id string 是 搜索结果中的列表ID

退货:

{
  "listing_id": "1564592031413917",
  "title": "Malt Miller 35ltr Brew Kettle",
  "price": "£95",
  "location": "Swindon, Wiltshire",
  "description": "Used but now upgrading my kit.",
  "condition": "Used – like new",
  "listed_date": "Listed 6 days ago in Swindon, Wiltshire",
  "url": "https://www.facebook.com/marketplace/item/1564592031413917"
}

AWS基岩代理核心部署

此服务器符合AWS Bedrock AgentCore运行时要求:

  • 无状态流式HTTP传输
  • 收听 0.0.0.0:8000
  • MCP端点位于 /mcp
# Install AgentCore toolkit
pip install bedrock-agentcore-starter-toolkit

# Configure and deploy
agentcore configure
agentcore launch

故障排除

首次设置/登录提示

服务器使用持久的Chromium浏览器配置文件。首次使用时(或Cookie过期时),脸书可能会显示信息警告或登录提示,阻止抓取。如果您遇到空白或混乱的结果,请在Playwright浏览器中手动打开一次Facebook Marketplace,忽略任何警告,然后重试。后续请求应在不受干预的情况下工作。

配置

环境变量 默认值 描述
HOST 0.0.0.0 服务器绑定地址
PORT 8000 服务器端口

项目结构

facebook_market_place/
├── server.py      # MCP server (FastMCP)
├── scraper.py     # Core scraping logic (Playwright)
├── pyproject.toml # Project dependencies
└── README.md      # This file

依赖项

  • Python 3.11+
  • FastMCP 2.x
  • 剧作家
  • 美丽的Soup4

许可证

MIT许可证-有关详细信息,请参阅许可证文件。

备注:此许可证仅涵盖代码。用户在使用本软件时仍有责任遵守Facebook的服务条款和所有适用法律。许可证不允许违反第三方服务条款或适用法规。

地理配置

此服务器配置了英国默认值:

  • 默认位置ID: 108339199186201 (联合王国)
  • 默认区域设置: en_GB

您可以通过为其他区域提供不同的位置ID来覆盖这些设置。

⚠️ 重要法律免责声明

此软件仅用于教育和研究目的。

  • 本项目旨在学习网络抓取、MCP服务器和浏览器自动化
  • 用户必须遵守Facebook的服务条款和robots.txt
  • 商业使用可能违反Facebook的条款和适用法律
  • 用户全权负责确保在其管辖范围内的合法使用
  • 作者对滥用此软件不承担任何责任
  • 始终遵守速率限制,并在请求之间实施适当的延迟
  • 考虑将Facebook的官方API用于生产应用程序

使用本软件即表示您已阅读并理解这些条款,并同意负责任地使用本软件,并遵守所有适用的法律和服务条款。

最后提醒

该项目演示了用于教育目的的网络抓取技术。始终优先考虑道德使用,尊重网站服务条款,并考虑为生产应用程序提供官方API。维护人员不对任何滥用此软件的行为负责。