Bright Data MCP:突破AI数据获取限制的革命性工具
文章目录
- 一、引言 | 传统方案的落后
- 二、Bright Data MCP
- 三、部署 MCP 服务器
- 3.1 本地自托管MCP服务器(选看)
- 3.1.1 简单调用API接口
- 3.2 远程调用MCP API
- 四、Python调用MCP API实时抓取 Google搜索结果
- 4.1 必看信息
- 4.2 搭建Python脚本
- 4.2.1 mcp_client_fixed.py 核心客户端类
- 4.2.2 interactive_client.py 交互式命令行界面
- 4.2.3 requirements.txt Python依赖文件
- 4.2.4 READEM.md 使用文档(补充流程)
- 4.3 HTTP方式调用MCP API
- 五、总结和分析
一、引言 | 传统方案的落后
传统AI应用依赖预训练数据集,在信息快速迭代的环境中捉襟见肘。静态数据库无法反映最新事实,致使AI输出过时甚至错误信息。预训练模型受限于知识截止日期,对新事件一无所知。
如果采用AI应用实时访问网页数据,采用传统爬虫频繁遭遇验证码、IP封锁等反爬措施,导致AI获取网页信息有限且缺乏真实性,使系统在关键决策时刻难以提供可靠支持。这一核心挑战使得AI实时获取动态网页信息成为技术难题,不仅需要突破反爬机制的限制,还需确保获取内容的完整性和准确性,以满足用户对实时信息的迫切需求。我发现了Bright Data MCP可以解决这个问题,在大语言模型(LLM)、人工智能代理和应用程序顺畅访问、搜索、爬取和浏览实时网络数据期间提供强大支持,同时规避封禁。
二、Bright Data MCP
MCP(模型上下文协议)是连接AI与外部世界的桥梁,它允许AI模型与各类工具、数据源建立安全的双向通信。作为中间层,MCP使AI应用能向外部资源请求信息并获取响应,突破了模型的知识局限,让AI能获取实时数据并执行复杂任务。这一标准化协议为AI生态系统的开放协作奠定了基础,显著提升了AI应用的实用价值。
Bright Data MCP是一款突破性的模型上下文协议服务器,由网络数据领域的权威团队Bright Data精心打造。作为专为公共网络访问设计的尖端解决方案,它赋予大型语言模型(LLMs)、智能代理和应用程序前所未有的能力——实时访问、智能发现并精准提取网络数据,同时巧妙规避地理限制和复杂的反爬虫机制。
该工具与Claude Desktop、Cursor等多种客户端实现了无缝集成,并提供可选的远程浏览器自动化功能,为用户创造流畅的操作体验。凭借其强大的技术架构和灵活的适应性,Bright Data MCP成为需要实时网络数据支持的各类应用场景的理想之选,为网络爬虫和数据采集任务树立了新标准。比如访问API,支持静态与动态网页等场景。
免费额度:每月 5,000 次请求,前 3 个月免费!
Bright Data MCP(Machine Concurrent Proxy)是一款强大的网络数据采集工具,具有以下显著优势:
【核心优势】
- 自动维护代理池:智能管理大规模代理资源,确保高可用性和稳定性
- 自动解锁功能:能够绕过常见的网站防护机制和访问限制
- JavaScript渲染支持:自动处理动态加载内容,确保完整数据采集
- 多种运行模式:
- Rapid模式:适合高速、大规模数据采集
- Pro模式:提供更高级的解锁能力和浏览器仿真
【技术特性】
- URL参数控制:通过简单参数调整工具行为
- unlocker:启用高级解锁功能
- browser:控制浏览器仿真行为
- pro=1:切换至专业模式
- 广泛兼容性:支持Claude、Cursor、各类语言模型等多种客户端集成
- 远程浏览器自动化:提供可选的浏览器自动化功能,增强数据采集能力
三、部署 MCP 服务器
目前MCP 服务器支持远程托管与本地部署两种部署方式,个人是比较推荐远程托管调用MCP服务,本地部署可能比较适合一些高级用户,存在一些环境上的需求。
两种部署方式:
- 远程(托管)MCP:Bright Data 云端托管,无需自行搭建。远程 MCP 快速入门
- 本地(自托管)MCP:您可以在本地或私有云环境中部署。本地 MCP 快速入门
这里我们选取其中一种方式,在Claude Desktop Extension中调用MCP实现网页问答即可。为了减少学习的成本,就可以快速上手调用MCP进行服务,就采用远端托管进行实战演示。同时会提供另外一种本地部署的策略或者思路。
注意:为了突出主要内容,关于环境安装或者一些其他问题会在文件末尾提供
3.1 本地自托管MCP服务器(选看)
(1). 先决条件:
- Bright Data账号
- Bright Data API密钥
- Node.js环境(确保最新版本)
如果您更喜欢使用不同的区域名称,可以在配置中使用
WEB_UNLOCKER_ZONE
环境变量来指定它
(2). 基本配置
转到 AI编程引用-> 设置 -> 开发人员 -> 编辑配置 ->
config.json
以包含以下内容:{ "mcpServers": {"Bright Data": {"command": "npx","args": ["@brightdata/mcp"],"env": {"API_TOKEN": "<insert your api key from https://brightdata.com/cp/setting/users>" (替换Bright Data API密钥)}} } }
【高级配置】:
如果要使用速率限制或自定义区域等高级功能,可以添加更多环境变量:
{ "mcpServers": {"Bright Data": {"command": "npx","args": ["@brightdata/mcp"],"env": {"API_TOKEN": "<insert your api key from https://brightdata.com/cp/setting/users>", "WEB_UNLOCKER_ZONE": "<Optional - if you want to use a specific name for web_unlocker, the name goes here. If not - REMOVE this field>","BROWSER_ZONE": "<Optional - if you want to use a specific name for browser_api, the name goes here. If not - REMOVE this field>","RATE_LIMIT": "<Optional - rate limit format, possible values: limit/time+unit, e.g., 100/1h, 50/30m, 10/5s. If not in use - REMOVE this field>","ADVANCED_MODE":"<Optional - deafult : false set to true if you want to expose all 60+ tools>" }} } }
3.1.1 简单调用API接口
我们可以在Trae软件中,配置下Bright Data MCP提供的JSON配置文件,进行调用。
该API密钥会更新,大家可以换成自己的。
参数:
{"url": "https://www.flightsfrom.com/JFK-LHR"
}
响应:
Direct (non-stop) flights from New York to London - schedules - FlightsFrom.com [](/)**New York** JFKYour search did not result in any matches. Please try again.**London** LHRYour search did not result in any matches. Please try again.Your searches did not result in any direct flight matches. Maybe you want to fly with stops instead?### Menu* [Home](/)
* [Search airport](/)
* [Compare prices](/outbound/search?from=JFK&to=LHR&label=menu)
* [Accommodation](/book/hotels?label=menu)
* [Car rentals](/book/cars?label=menu)* [All destinations from New York (JFK)](/JFK)
* [Airports in USA](/usa)
* [Airports in the USA](/usa)
* [Airports in the UK](/usa)
* [Airports in Canada](/usa)* [Top 100 biggest airports](/top100airports)
* [Top 100 biggest airlines](/top100airlines)
* [News & fun facts](/articles)* * *FlightsFrom.com is a useful website for finding airline routes and flight schedules globally. The idea is being able to explore destination opportunities through non-stop flights from a specific airport. It's a tool to set up your business meeting or weekend holiday based on your timeschedule and your closest airport.* [Read more about the idea behind FlightsFrom.com](/en/about-us)Round tripRound tripOne-way1 adult\-+1 adults\-+0 childrenEconomyEconomyBusinessAD [+1 (831) 271-0274](tel:+18312710274): Unpublished Flight Rates **From to**CHECK PRICES* * *AD [+1 (831) 271-0274](tel:+18312710274): Unpublished Flight Rates **From New York to London**# Direct (non-stop) flights from New York to LondonAll flight schedules from **John F Kennedy International , New York , USA** to **Heathrow, United Kingdom**. This route is operated by 5 airlines and the flight time is 7 hours and 36 minutes. The distance is 3461 miles.[Monthly schedule](#ff-tab-0)[Week schedules](#ff-tab-1)[American Airlines](#ff-tab-1)[British Airways](#ff-tab-2)[Delta Air Lines](#ff-tab-3)[Virgin Atlantic](#ff-tab-4)[JetBlue Airways](#ff-tab-5)[Airlines](#direct-airlines)[Aircrafts](#aircrafts)Price search**JFK** John F Kennedy InternationalNew York , NY , USA**LHR** HeathrowLondon, United Kingdom[CHANGE DIRECTION](/LHR-JFK)Flight time**7h 36m**Flight distance**3461mi, 5569km**VIEW LARGER MAP[SHOW ROUTE ON THE MAP EXPLORER](/explorer/JFK?mapview#LHR)CHECK PRICESUSA[JFK](/JFK)New York , NYUnited Kingdom[LHR](/LHR)LondonDistance3461 miles · (5569 km)[CHANGE DIRECTION](/LHR-JFK)Flight time7 hours and 36 minutes### Airlines with direct flights from New York (JFK) to London (LHR)* American AirlinesOneworldSMTWTFSBusiness available4 daily flights* British AirwaysOneworldSMTWTFSBusiness available8 daily flights* Delta Air LinesSky TeamSMTWTFSBusiness available2 daily flights* Virgin AtlanticSky TeamSMTWTFSBusiness available6 daily flights* JetBlue AirwaysSMTWTFSLow-cost airline2 daily flightsSELECT DATES & SHOW PRICESJFK LHRSelect datesCheck pricesMONTHLYWEEKLYWEEKLYWEEKLYWEEKLYWEEKLY### New York (JFK) to London (LHR) flight scheduleThe monthly calendar shows every direct flight departure from John F Kennedy International (JFK) with all airlines. Click on a date to see a list of flights or search for the best prices. American Airlines JetBlue British Airways Delta Virgin Atlantic[View return flights from LHR to JFK](/LHR-JFK)### American Airlines flight schedule from New York to LondonAll weekly departures with American Airlines. The week calendar shows every flight departure from New York (JFK) to London (LHR). Click on a blue date to see a list of flights.Week 35 (Aug 25 - Aug 31)* Week 33 (Aug 11 - Aug 17)
* Week 34 (Aug 18 - Aug 24)
* Week 35 (Aug 25 - Aug 31)
* Week 36 (Sep 1 - Sep 7)
* Week 37 (Sep 8 - Sep 14)
* Week 38 (Sep 15 - Sep 21)
* Week 39 (Sep 22 - Sep 28)
* Week 40 (Sep 29 - Oct 5)
* Week 41 (Oct 6 - Oct 12)
* Week 42 (Oct 13 - Oct 19)
* Week 43 (Oct 20 - Oct 26)
* Week 44 (Oct 27 - Nov 2)
* Week 45 (Nov 3 - Nov 9)
* Week 46 (Nov 10 - Nov 16)
* Week 47 (Nov 17 - Nov 23)
* Week 48 (Nov 24 - Nov 30)
* Week 49 (Dec 1 - Dec 7)
* Week 50 (Dec 8 - Dec 14)
* Week 51 (Dec 15 - Dec 21)
* Week 52 (Dec 22 - Dec 28)
* Week 01 (Dec 29 - Jan 4)
* Week 02 (Jan 5 - Jan 11)
* Week 03 (Jan 12 - Jan 18)
* Week 04 (Jan 19 - Jan 25)
* Week 05 (Jan 26 - Feb 1)
* Week 06 (Feb 2 - Feb 8)
* Week 07 (Feb 9 - Feb 15)
* Week 08 (Feb 16 - Feb 22)
* Week 09 (Feb 23 - Mar 1)
* Week 10 (Mar 2 - Mar 8)
* Week 11 (Mar 9 - Mar 15)
* Week 12 (Mar 16 - Mar 22)
* Week 13 (Mar 23 - Mar 29)
* Week 14 (Mar 30 - Apr 5)
* Week 15 (Apr 6 - Apr 12)
* Week 16 (Apr 13 - Apr 19)
* Week 17 (Apr 20 - Apr 26)
* Week 18 (Apr 27 - May 3)
* Week 19 (May 4 - May 10)
* Week 20 (May 11 - May 17)
* Week 21 (May 18 - May 24)
* Week 22 (May 25 - May 31)
* Week 23 (Jun 1 - Jun 7)
* Week 24 (Jun 8 - Jun 14)
* Week 25 (Jun 15 - Jun 21)
* Week 26 (Jun 22 - Jun 28)
* Week 27 (Jun 29 - Jul 5)
* Week 28 (Jul 6 - Jul 12)
* Week 29 (Jul 13 - Jul 19)
* Week 30 (Jul 20 - Jul 26)
* Week 31 (Jul 27 - Aug 2)
* Week 32 (Aug 3 - Aug 9)
* Week 33 (Aug 10 - Aug 16)
* Week 34 (Aug 17 - Aug 23)
* Week 35 (Aug 24 - Aug 30)
* Week 36 (Aug 31 - Sep 6)
* Week 37 (Sep 7 - Sep 13)
* Week 38 (Sep 14 - Sep 20)
* Week 39 (Sep 21 - Sep 27)
* Week 40 (Sep 28 - Oct 4)FlightMonAug 25TueAug 26WedAug 27ThuAug 28FriAug 29SatAug 30SunAug 31AA14209:4509:4509:4509:4509:4509:4509:45AA10018:1018:1018:1018:1018:1018:1018:10AA10619:2919:2919:2919:2919:2919:2919:29AA10422:5522:5522:5522:5522:5522:5522:55### British Airways flight schedule from New York to LondonAll weekly departures with British Airways. The week calendar shows every flight departure from New York (JFK) to London (LHR). Click on a blue date to see a list of flights.Week 35 (Aug 25 - Aug 31)* Week 33 (Aug 11 - Aug 17)
* Week 34 (Aug 18 - Aug 24)
* Week 35 (Aug 25 - Aug 31)
* Week 36 (Sep 1 - Sep 7)
* Week 37 (Sep 8 - Sep 14)
* Week 38 (Sep 15 - Sep 21)
* Week 39 (Sep 22 - Sep 28)
* Week 40 (Sep 29 - Oct 5)
* Week 41 (Oct 6 - Oct 12)
* Week 42 (Oct 13 - Oct 19)
* Week 43 (Oct 20 - Oct 26)
* Week 44 (Oct 27 - Nov 2)
* Week 45 (Nov 3 - Nov 9)
* Week 46 (Nov 10 - Nov 16)
* Week 47 (Nov 17 - Nov 23)
* Week 48 (Nov 24 - Nov 30)
* Week 49 (Dec 1 - Dec 7)
* Week 50 (Dec 8 - Dec 14)
* Week 51 (Dec 15 - Dec 21)
* Week 52 (Dec 22 - Dec 28)
* Week 01 (Dec 29 - Jan 4)
* Week 02 (Jan 5 - Jan 11)
* Week 03 (Jan 12 - Jan 18)
* Week 04 (Jan 19 - Jan 25)
* Week 05 (Jan 26 - Feb 1)
* Week 06 (Feb 2 - Feb 8)
* Week 07 (Feb 9 - Feb 15)
* Week 08 (Feb 16 - Feb 22)
* Week 09 (Feb 23 - Mar 1)
* Week 10 (Mar 2 - Mar 8)
* Week 11 (Mar 9 - Mar 15)
* Week 12 (Mar 16 - Mar 22)
* Week 13 (Mar 23 - Mar 29)
* Week 14 (Mar 30 - Apr 5)
* Week 15 (Apr 6 - Apr 12)
* Week 16 (Apr 13 - Apr 19)
* Week 17 (Apr 20 - Apr 26)
* Week 18 (Apr 27 - May 3)
* Week 19 (May 4 - May 10)
* Week 20 (May 11 - May 17)
* Week 21 (May 18 - May 24)
* Week 22 (May 25 - May 31)
* Week 23 (Jun 1 - Jun 7)
* Week 24 (Jun 8 - Jun 14)
* Week 25 (Jun 15 - Jun 21)
* Week 26 (Jun 22 - Jun 28)
* Week 27 (Jun 29 - Jul 5)
* Week 28 (Jul 6 - Jul 12)
* Week 29 (Jul 13 - Jul 19)
* Week 30 (Jul 20 - Jul 26)
* Week 31 (Jul 27 - Aug 2)
* Week 32 (Aug 3 - Aug 9)
* Week 33 (Aug 10 - Aug 16)
* Week 34 (Aug 17 - Aug 23)
* Week 35 (Aug 24 - Aug 30)
* Week 36 (Aug 31 - Sep 6)
* Week 37 (Sep 7 - Sep 13)
* Week 38 (Sep 14 - Sep 20)
* Week 39 (Sep 21 - Sep 27)
* Week 40 (Sep 28 - Oct 4)FlightMonAug 25TueAug 26WedAug 27ThuAug 28FriAug 29SatAug 30SunAug 31BA17807:5007:5007:5007:5007:5007:5007:50BA11218:3018:3018:3018:3018:3018:3018:30BA17418:4518:4518:4518:4518:4518:4518:45BA17619:3019:3019:3019:3019:3019:3019:30BA11620:0520:0520:0520:0520:0520:0520:05BA17220:5520:5520:5520:5520:5520:5520:55BA11421:3021:3021:3021:3021:3021:3021:30BA18223:1023:1023:1023:1023:1023:1023:10### Delta Air Lines flight schedule from New York to LondonAll weekly departures with Delta Air Lines. The week calendar shows every flight departure from New York (JFK) to London (LHR). Click on a blue date to see a list of flights.Week 35 (Aug 25 - Aug 31)* Week 33 (Aug 11 - Aug 17)
* Week 34 (Aug 18 - Aug 24)
* Week 35 (Aug 25 - Aug 31)
* Week 36 (Sep 1 - Sep 7)
* Week 37 (Sep 8 - Sep 14)
* Week 38 (Sep 15 - Sep 21)
* Week 39 (Sep 22 - Sep 28)
* Week 40 (Sep 29 - Oct 5)
* Week 41 (Oct 6 - Oct 12)
* Week 42 (Oct 13 - Oct 19)
* Week 43 (Oct 20 - Oct 26)
* Week 44 (Oct 27 - Nov 2)
* Week 45 (Nov 3 - Nov 9)
* Week 46 (Nov 10 - Nov 16)
* Week 47 (Nov 17 - Nov 23)
* Week 48 (Nov 24 - Nov 30)
* Week 49 (Dec 1 - Dec 7)
* Week 50 (Dec 8 - Dec 14)
* Week 51 (Dec 15 - Dec 21)
* Week 52 (Dec 22 - Dec 28)
* Week 01 (Dec 29 - Jan 4)
* Week 02 (Jan 5 - Jan 11)
* Week 03 (Jan 12 - Jan 18)
* Week 04 (Jan 19 - Jan 25)
* Week 05 (Jan 26 - Feb 1)
* Week 06 (Feb 2 - Feb 8)
* Week 07 (Feb 9 - Feb 15)
* Week 08 (Feb 16 - Feb 22)
* Week 09 (Feb 23 - Mar 1)
* Week 10 (Mar 2 - Mar 8)
* Week 11 (Mar 9 - Mar 15)
* Week 12 (Mar 16 - Mar 22)
* Week 13 (Mar 23 - Mar 29)
* Week 14 (Mar 30 - Apr 5)
* Week 15 (Apr 6 - Apr 12)
* Week 16 (Apr 13 - Apr 19)
* Week 17 (Apr 20 - Apr 26)
* Week 18 (Apr 27 - May 3)
* Week 19 (May 4 - May 10)
* Week 20 (May 11 - May 17)
* Week 21 (May 18 - May 24)
* Week 22 (May 25 - May 31)
* Week 23 (Jun 1 - Jun 7)
* Week 24 (Jun 8 - Jun 14)
* Week 25 (Jun 15 - Jun 21)
* Week 26 (Jun 22 - Jun 28)
* Week 27 (Jun 29 - Jul 5)
* Week 28 (Jul 6 - Jul 12)
* Week 29 (Jul 13 - Jul 19)
* Week 30 (Jul 20 - Jul 26)
* Week 31 (Jul 27 - Aug 2)
* Week 32 (Aug 3 - Aug 9)
* Week 33 (Aug 10 - Aug 16)
* Week 34 (Aug 17 - Aug 23)
* Week 35 (Aug 24 - Aug 30)
* Week 36 (Aug 31 - Sep 6)
* Week 37 (Sep 7 - Sep 13)
* Week 38 (Sep 14 - Sep 20)
* Week 39 (Sep 21 - Sep 27)
* Week 40 (Sep 28 - Oct 4)FlightMonAug 25TueAug 26WedAug 27ThuAug 28FriAug 29SatAug 30SunAug 31DL120:3020:3020:3020:2920:2920:2920:29DL322:0022:3022:0022:0022:0022:0022:00### Virgin Atlantic flight schedule from New York to LondonAll weekly departures with Virgin Atlantic. The week calendar shows every flight departure from New York (JFK) to London (LHR). Click on a blue date to see a list of flights.Week 35 (Aug 25 - Aug 31)* Week 33 (Aug 11 - Aug 17)
* Week 34 (Aug 18 - Aug 24)
* Week 35 (Aug 25 - Aug 31)
* Week 36 (Sep 1 - Sep 7)
* Week 37 (Sep 8 - Sep 14)
* Week 38 (Sep 15 - Sep 21)
* Week 39 (Sep 22 - Sep 28)
* Week 40 (Sep 29 - Oct 5)
* Week 41 (Oct 6 - Oct 12)
* Week 42 (Oct 13 - Oct 19)
* Week 43 (Oct 20 - Oct 26)
* Week 44 (Oct 27 - Nov 2)
* Week 45 (Nov 3 - Nov 9)
* Week 46 (Nov 10 - Nov 16)
* Week 47 (Nov 17 - Nov 23)
* Week 48 (Nov 24 - Nov 30)
* Week 49 (Dec 1 - Dec 7)
* Week 50 (Dec 8 - Dec 14)
* Week 51 (Dec 15 - Dec 21)
* Week 52 (Dec 22 - Dec 28)
* Week 01 (Dec 29 - Jan 4)
* Week 02 (Jan 5 - Jan 11)
* Week 03 (Jan 12 - Jan 18)
* Week 04 (Jan 19 - Jan 25)
* Week 05 (Jan 26 - Feb 1)
* Week 06 (Feb 2 - Feb 8)
* Week 07 (Feb 9 - Feb 15)
* Week 08 (Feb 16 - Feb 22)
* Week 09 (Feb 23 - Mar 1)
* Week 10 (Mar 2 - Mar 8)
* Week 11 (Mar 9 - Mar 15)
* Week 12 (Mar 16 - Mar 22)
* Week 13 (Mar 23 - Mar 29)
* Week 14 (Mar 30 - Apr 5)
* Week 15 (Apr 6 - Apr 12)
* Week 16 (Apr 13 - Apr 19)
* Week 17 (Apr 20 - Apr 26)
* Week 18 (Apr 27 - May 3)
* Week 19 (May 4 - May 10)
* Week 20 (May 11 - May 17)
* Week 21 (May 18 - May 24)
* Week 22 (May 25 - May 31)
* Week 23 (Jun 1 - Jun 7)
* Week 24 (Jun 8 - Jun 14)
* Week 25 (Jun 15 - Jun 21)
* Week 26 (Jun 22 - Jun 28)
* Week 27 (Jun 29 - Jul 5)
* Week 28 (Jul 6 - Jul 12)
* Week 29 (Jul 13 - Jul 19)
* Week 30 (Jul 20 - Jul 26)
* Week 31 (Jul 27 - Aug 2)
* Week 32 (Aug 3 - Aug 9)
* Week 33 (Aug 10 - Aug 16)
* Week 34 (Aug 17 - Aug 23)
* Week 35 (Aug 24 - Aug 30)
* Week 36 (Aug 31 - Sep 6)
* Week 37 (Sep 7 - Sep 13)
* Week 38 (Sep 14 - Sep 20)
* Week 39 (Sep 21 - Sep 27)
* Week 40 (Sep 28 - Oct 4)FlightMonAug 25TueAug 26WedAug 27ThuAug 28FriAug 29SatAug 30SunAug 31VS2608:1008:1008:1008:1008:1008:1008:10VS418:0018:0018:0018:0018:0018:0018:00VS1019:0019:0019:0019:0019:0019:0019:00VS4621:0021:0021:0021:0021:0021:0021:00VS15421:3021:3021:3021:3021:3021:3021:30VS13823:2523:2523:2523:2523:2523:2523:25### JetBlue Airways flight schedule from New York to LondonAll weekly departures with JetBlue Airways. The week calendar shows every flight departure from New York (JFK) to London (LHR). Click on a blue date to see a list of flights.Week 35 (Aug 25 - Aug 31)* Week 33 (Aug 11 - Aug 17)
* Week 34 (Aug 18 - Aug 24)
* Week 35 (Aug 25 - Aug 31)
* Week 36 (Sep 1 - Sep 7)
* Week 37 (Sep 8 - Sep 14)
* Week 38 (Sep 15 - Sep 21)
* Week 39 (Sep 22 - Sep 28)
* Week 40 (Sep 29 - Oct 5)
* Week 41 (Oct 6 - Oct 12)
* Week 42 (Oct 13 - Oct 19)
* Week 43 (Oct 20 - Oct 26)
* Week 44 (Oct 27 - Nov 2)
* Week 45 (Nov 3 - Nov 9)
* Week 46 (Nov 10 - Nov 16)
* Week 47 (Nov 17 - Nov 23)
* Week 48 (Nov 24 - Nov 30)
* Week 49 (Dec 1 - Dec 7)
* Week 50 (Dec 8 - Dec 14)
* Week 51 (Dec 15 - Dec 21)
* Week 52 (Dec 22 - Dec 28)
* Week 01 (Dec 29 - Jan 4)
* Week 02 (Jan 5 - Jan 11)
* Week 03 (Jan 12 - Jan 18)
* Week 04 (Jan 19 - Jan 25)
* Week 05 (Jan 26 - Feb 1)
* Week 06 (Feb 2 - Feb 8)
* Week 07 (Feb 9 - Feb 15)
* Week 08 (Feb 16 - Feb 22)
* Week 09 (Feb 23 - Mar 1)
* Week 10 (Mar 2 - Mar 8)
* Week 11 (Mar 9 - Mar 15)
* Week 12 (Mar 16 - Mar 22)
* Week 13 (Mar 23 - Mar 29)
* Week 14 (Mar 30 - Apr 5)
* Week 15 (Apr 6 - Apr 12)
* Week 16 (Apr 13 - Apr 19)
* Week 17 (Apr 20 - Apr 26)
* Week 18 (Apr 27 - May 3)
* Week 19 (May 4 - May 10)
* Week 20 (May 11 - May 17)
* Week 21 (May 18 - May 24)
* Week 22 (May 25 - May 31)
* Week 23 (Jun 1 - Jun 7)
* Week 24 (Jun 8 - Jun 14)
* Week 25 (Jun 15 - Jun 21)
* Week 26 (Jun 22 - Jun 28)
* Week 27 (Jun 29 - Jul 5)
* Week 28 (Jul 6 - Jul 12)
* Week 29 (Jul 13 - Jul 19)
* Week 30 (Jul 20 - Jul 26)
* Week 31 (Jul 27 - Aug 2)
* Week 32 (Aug 3 - Aug 9)
* Week 33 (Aug 10 - Aug 16)
* Week 34 (Aug 17 - Aug 23)
* Week 35 (Aug 24 - Aug 30)
* Week 36 (Aug 31 - Sep 6)
* Week 37 (Sep 7 - Sep 13)
* Week 38 (Sep 14 - Sep 20)
* Week 39 (Sep 21 - Sep 27)
* Week 40 (Sep 28 - Oct 4)FlightMonAug 25TueAug 26WedAug 27ThuAug 28FriAug 29SatAug 30SunAug 31B6110708:4508:4508:4508:4508:4508:4508:45B6720:5920:5920:5920:5920:5921:0020:59Flight time**6h 45m - 7h 36m**Earliest flight**07:50**Last flight**23:25**Distance**3461 miles (5569 km)**Cheapest month**October**Airlines**5 ([Show](#direct-airlines))**Flights per week**147**Departing Terminal (JFK)**Terminal 4, 5 or 8**Arriving Terminal (LHR)**Terminal 2, 3 or 5**America/New York (UTC-4)Europe/London (UTC+1)**LHR +5 hours ahead**### Arriving at Heathrow (LHR)Heathrow (LHR) is the largest airport in United Kingdom and is based in London. You can fly to 217 destinations with 78 airlines in scheduled passenger traffic.[Show all flights from LHR](/LHR)Best prices on rental cars in LondonCompare prices and book now with free cancellation.[SEARCH FOR RENTAL CARS](/outbound/search?alt=cars&alt-location=London,United Kingdom&page=JFK-LHR)Hotel deals in London with free cancellation[HOTEL PRICES](/outbound/search?alt=hotels&alt-location=London,United Kingdom&page=JFK-LHR)Top 10 things to do in LondonFind out what other travelers are looking for in London.[SHOW ACTIVITIES](/r/go/eyJpdiI6IlBtenBrUDNNWStXUHRcL3ZVeTY2MG13PT0iLCJ2YWx1ZSI6IjJQK3dFaWVQTko5Z0RhS2VHU2YzZnRKQXRGVkpreWJaV2ZwU0hZREk5XC9VZm5hK040N3krY2hZVG5rZktrTWxjbHNcL2liVVRcL0hkWTJOWkdZMlZUV1QwWTlvMm9TckJkbkxqd1Rjd29NQndUMnlWNVVzZEdnT2w1UTR2dTZQOUVlWTBWNVBiXC9oa08wT0FINDRjRDBmMFRZbzh6TVk4dzR6U0JBSnVJSm4xZXc9IiwibWFjIjoiOGI5OTM3OTI0ZmJhYTJhMjA0NDFiZTI2ZGIwMGMxYzhjZDU4YzM1MTQyMDIzNThmZjhjZjlkMmI2YjA2ZTAxZSJ9)### Departing from John F Kennedy (JFK) , New YorkJohn F Kennedy International (JFK) is a large airport based in New York, USA. You can fly to 197 destinations with 72 airlines in scheduled passenger traffic.[Show all flights from JFK](/JFK)### Airlines with alternative airports from New York to LondonThe airlines below are departing from or arriving to other airports in the same city or very close.Air IndiaStar AllianceNewark Liberty International HeathrowDuration6 hours and 55 minutesBritish AirwaysOneworldNewark Liberty International HeathrowDuration7 hours and 05 minutesUnitedStar AllianceNewark Liberty International HeathrowDuration7 hours and 30 minutesVirgin AtlanticSky TeamNewark Liberty International HeathrowDuration7 hours and 10 minutes[Show detailed flight schedule from EWR to LHR](/EWR-LHR)Primera Air ScandinaviaNewark Liberty International StanstedDuration7 hours and 10 minutes[Show detailed flight schedule from EWR to STN](/EWR-STN)British AirwaysOneworldJohn F Kennedy International CityDuration8 hours and 25 minutes[Show detailed flight schedule from JFK to LCY](/JFK-LCY)British AirwaysOneworldJohn F Kennedy International GatwickDuration7 hours and 05 minutesNorwegian Air ShuttleJohn F Kennedy International GatwickDuration6 hours and 31 minutesNorwegian Air UKJohn F Kennedy International GatwickDuration7 hours and 50 minutesVirgin AtlanticSky TeamJohn F Kennedy International GatwickDuration7 hours and 20 minutesJetBlueJohn F Kennedy International GatwickDuration7 hours and 25 minutesNorseJohn F Kennedy International GatwickDuration7 hours and 15 minutesDeltaSky TeamJohn F Kennedy International GatwickDuration7 hours and 25 minutesNorse AtlanticJohn F Kennedy International GatwickDuration7 hours and 05 minutes[Show detailed flight schedule from JFK to LGW](/JFK-LGW)### New York - London flight price statistics$590ApproximateThe numbers are avarage prices found based on user searches for direct flights between John F Kennedy International and Heathrow. Its calculated from the cheapest prices found per month for a round-trip with 1 adult and can vary depending on the amount of data we have for this particular route.**$544**
Jan**$544**
Feb**$546**
Mar**$547**
Apr**$1818**
May**$645**
Jun**$539**
Jul**$553**
Aug**$566**
Sep**$526**
Oct**$574**
Nov**$574**
DecApproximate prices for one round-trip flight from **New York (JFK)** to **London (LHR)**. Graph is not to scale.CLICK HERE FOR EXACT PRICES### Type of aircraft(s) on this routeBelow is a list of aircraft types we have within our database with flights on this route. You can also see the aircrafts **seat capacity** together with classes.Boeing 777-200 / 200ERAmerican Airlines273 seats(24 business class, 24 premium economy)Boeing 777-300ERAmerican Airlines304 seats(8 first class, 28 business class, 28 premium economy)Boeing 777British Airways267 seats(4 first class, 42 business class, 42 premium economy)Boeing 787-10British Airways256 seats(8 first class, 35 business class, 35 premium economy)Boeing 777-300ERBritish Airways256 seats(8 first class, 40 business class, 40 premium economy)Boeing 767-400 PassengerDelta Air Lines238 seats(20 business class, 20 premium economy)Airbus A330-900neoDelta Air Lines281 seats(28 business class, 28 premium economy)Boeing 787-9Virgin Atlantic258 seats(35 business class, 35 premium economy)Airbus A330-900neoVirgin Atlantic262 seats(46 business class, 46 premium economy)Airbus A350-1000Virgin Atlantic360 seats(56 business class, 56 premium economy)Airbus A321neoJetBlue Airways167 seatsROUTE EXPLORING### John F Kennedy International - all destinationsWith FlightsFrom.com’s brilliant search features you can explore all non-stop flights from a specific airport. Simply select your preferred airport to get an overview of every single non-stop flight offered. Click on one of the routes to get information about which airline’s operate the route, when the next scheduled flight is or to filter your search even more.[EXPLORE ALL DESTINATIONS](/JFK)### Select your flight detailsRound trip1 adultEconomyRound trip One wayAdults\-1+Children\-0+Infants\-0+Economy BusinessYou may have missed to select a date. Please check the calendar. If you dont know your date, use on the button "I dont know my dates"AD [+1 (831) 271-0274](tel:+18312710274): Unpublished Flight Rates From **New York to London**I HAVE NO DATESCHECK PRICESCheck accommodation with our partner AD [+1 (831) 271-0274](tel:+18312710274): Unpublished Flight Rates From **New York to London**### Frequently asked questions FAQ* How long does a flight from New York (JFK) to London (LHR) take?This long-haul flight from New York (JFK) to London (LHR) takes about 7 hours and 5 minutes.* How many flights per day are there on this route?There are 22 direct flights every day.* What are the flight numbers on the route New York to London?The flight numbers are AA100, AA104, AA106, AA142, B67, B61107, BA112, BA114 together with 17 additional flights.* Which airports will I be using when flying from New York to London?From New York you fly out from John F Kennedy International (JFK) and you'll be landing at Gatwick (LGW), Heathrow (LHR).* What aircraft types are flying on this route?American Airlines, British Airways, Delta, Virgin Atlantic, and JetBlue all flyes the Boeing 787 Dreamliner on this route.* How many airlines fly non-stop from New York (JFK) to London (LHR)?Five airlines. American Airlines, British Airways, Delta, Virgin Atlantic and JetBlue have non-stop flights to London.* What terminals does the aircrafts depart from and on what terminals do they arrive?Flights are arriving at terminal 3 or 2 in London (LHR). All flights to London are departing from terminal 8 or 5 at New York (JFK).[VIEW IN
MAP EXPLORER](/explorer/JFK?mapview#LHR) ##### Non-stop flights from JFK to LHR3461 miles (5569 km) · 7 hours and 36 minutesCHECK PRICESNew York (JFK) updatesSubscribe to our newsletter and be the first to know about the latest news and flight route updates.Your email addressJoin for freeYou may opt-out at any time#### Popular routes from New York####  American Airlines routes[New York (JFK) - Los Angeles (LAX)](/JFK-LAX)[New York (JFK) - Miami (MIA)](/JFK-MIA)[New York (JFK) - Charlotte (CLT)](/JFK-CLT)[New York (JFK) - Boston (BOS)](/JFK-BOS)[New York (JFK) - San Francisco (SFO)](/JFK-SFO)_For more destinations from New York with American Airlines (AA), check out the [American Airlines route map](/AA) ._####  Delta Air Lines routes[New York (JFK) - Los Angeles (LAX)](/JFK-LAX)[New York (JFK) - Atlanta (ATL)](/JFK-ATL)[New York (JFK) - San Francisco (SFO)](/JFK-SFO)[New York (JFK) - Orlando (MCO)](/JFK-MCO)[New York (JFK) - Boston (BOS)](/JFK-BOS)_For more destinations from New York with Delta Air Lines (DL), check out the [Delta Air Lines route map](/DL) ._####  JetBlue Airways routes[New York (JFK) - Los Angeles (LAX)](/JFK-LAX)[New York (JFK) - Orlando (MCO)](/JFK-MCO)[New York (JFK) - San Juan (SJU)](/JFK-SJU)[New York (JFK) - Santiago (STI)](/JFK-STI)[New York (JFK) - Fort Lauderdale (FLL)](/JFK-FLL)_For more destinations from New York with JetBlue Airways (B6), check out the [JetBlue Airways route map](/B6) ._* [USA](/usa)
* [New York (JFK)](/JFK)
* London (LHR)AD [+1 (831) 271-0274](tel:+18312710274): Unpublished Flight Rates From **New York to London**### What is FlightsFrom?_FlightsFrom.com is a useful website for finding airline routes and flight schedules globally. The idea is being able to explore destination opportunities through non-stop flights from a specific airport. It's a tool to set up your business meeting or weekend holiday based on your timeschedule and your closest airport.__Part of its appeal is that it just makes trips easier to plan; you see the departure times of every non-stop flight in a list.__\- MSN.com__I always wondered where you could fly direct from a particular airport (Burbank, I’m looking at you) and those answers can be tough to find. Not anymore!__\- Rich on tech__Many mainstream sites don’t list low-cost carriers or link transoceanic flights to regionally based carriers that can provide less expensive options. For that, you need a bigger tool kit… (Hint: search by destination airport at FlightsFrom.com)__\- The New York Times__Many low-cost carriers airlines prevent their flights from showing up on some of these (read Vayama or Google Flights) third-party travel websites. If you want a chance to view all local departures, try using FlightsFrom.com__\- Lifehacker_* * *### Enjoying our website? Try our newsletter.Wish to receive airport and airline updates?
Enter your email below!Subscribe### Social MediaDon't want to miss anything new?
Follow us[](https://www.instagram.com/flightsfrom/)[Select airport](/)[Airport map](/map)[Fun facts](/articles)[Privacy policy](https://www.flightsfrom.com/en/privacy-policy)[About FlightsFrom.com](https://www.flightsfrom.com/en/about-us)[](https://www.flightsfrom.com)Copyright 20
结果:
3.2 远程调用MCP API
(1). 先决条件
- Bright Data账号
- Bright Data API密钥
首先有Bright Data账号并且获得Bright Data API密钥。如果没有亮数据账号,现在注册,每月免费接收 5000 个请求。
获得Bright Data API密钥请保存起来,是不会显示第二次的。
(2). 选择链接方式
Bright Data MCP提供两种高效连接方式,满足不同场景需求:
-
SSE实时数据流:
https://mcp.brightdata.com/sse?token=YOUR_API_TOKEN
( 适用于需要持续接收服务器推送数据的实时应用场景) -
HTTP标准请求:
https://mcp.brightdata.com/mcp?token=YOUR_API_TOKEN
(支持流式传输,适合常规数据获取和处理任务)
安全提示:在实际部署中,请将链接中的
YOUR_API_TOKEN
替换为您的Bright Data授权密钥,确保API访问安全。
MCP server 提供丰富的工具提供调用。比如,等会我们需要实战演示的实时Goolge搜索。
四、Python调用MCP API实时抓取 Google搜索结果
4.1 必看信息
我认为它值得一条"二级标题",我在进行实战过程中遇到的问题和获得知识。如果我说的有问题,可以在评论区交流下,谢谢。
Bright Data的MCP服务设计理念是让用户通过特定的客户端工具或环境来使用它们的服务,而不是让用户直接通过编程方式(如REST API调用)来访问和控制MCP服务。
MCP的token主要用于客户端配置,而不是用于直接API调用。所以,当你尝试通过JSON配置文件直接配置MCP,可能会失败。
等等,你说的也不对呀!那为什么HTTP方式可以调用API呢?
对的,通过HTTP方式成功连接搭配MCP服务时,本质也是在调用MCP的API。这里的区别可能在于使用方式和访问级别:
【直接HTTP代理连接】:
- 这是使用MCP作为代理服务器的基本功能
- 当您配置HTTP代理连接时,您实际上是在使用MCP的"数据通道"功能
- 这种方式通常是被允许的,因为这是MCP的核心服务功能
【配置和管理API】:
- 这是用来配置、管理和控制MCP服务本身的API
- 包括创建新的代理配置、修改现有设置、查询使用统计等
- 这部分功能可能被限制只能通过官方工具或特定环境访问
所以,当我说"不是设计用于直接API调用"时,我指的主要是第二类API(配置和管理API),而不是基本的代理连接功能。
通过HTTP成功连接,是使用MCP的基本代理功能,当尝试JSON配置文件来管理或配置MCP服务时遇到的问题,可能时这些管理功能被限制了。
这种区分在代理服务中很常见:允许用户通过标准协议使用代理服务,但限制用户直接访问管理和配置API。
【Bright Data MCP服务通常需要通过以下方式访问】:
- 支持MCP协议的IDE环境
- mcp-remote工具
- Bright Data提供的官方客户端
4.2 搭建Python脚本
📁 文件结构概览
核心文件包括:mcp_client_fixed.py、interactive_client.py、requirements.txt、README.md**(Token换成你自己的API密钥,我肯定要更新的API的)**
python-mcp-client/
├── mcp_client_fixed.py # ✅ 修复版核心客户端(推荐使用)
├── mcp_client.py # 原始版核心客户端(有重复内容问题)
├── interactive_client.py # 交互式命令行界面
├── test_client.py # 测试脚本
├── requirements.txt # Python依赖文件
└── README.md # 使用说明文档
4.2.1 mcp_client_fixed.py 核心客户端类
主要功能:
- 🔑 API认证 - 通过URL参数传递Bright Data token
- 📡 HTTP通信 - 处理与Bright Data MCP服务器的通信
- 🔄 会话管理 - 维护会话ID和状态
- 📊 数据解析 - 解析Server-Sent Events格式的响应
- 🔍 搜索功能 - 支持Google/Bing/Yandex搜索
核心类和方法:
MCPClient
类 - 主要客户端类_send_request()
- 发送HTTP请求并显示详细API调用信息_parse_sse_data()
- 解析Server-Sent Events格式数据connect()
- 建立连接并创建会话initialize()
- 初始化MCP协议search()
- 执行搜索查询scrape()
- 抓取网页内容
源码:
import requests
import json
import time
from typing import Dict, Any, Optionalclass MCPClient:"""Python版本的MCP客户端,用于调用Bright Data的MCP服务"""def __init__(self, token: str):"""初始化MCP客户端Args:token: Bright Data的API token"""self.token = tokenself.base_url = f"https://mcp.brightdata.com/mcp?token={token}"self.session_id = Noneself.message_id = 1self.session = requests.Session()# 设置默认请求头self.session.headers.update({'Content-Type': 'application/json','Accept': 'application/json, text/event-stream','User-Agent': 'Python-MCP-Client/1.0'})def _parse_sse_data(self, sse_text: str) -> Dict[str, Any]:"""解析Server-Sent Events格式的数据Args:sse_text: SSE格式的文本Returns:解析后的JSON数据"""try:# 查找data:行lines = sse_text.split('\n')for line in lines:if line.startswith('data: '):json_str = line[6:] # 移除'data: '前缀# 确保正确的UTF-8编码if isinstance(json_str, bytes):json_str = json_str.decode('utf-8')data = json.loads(json_str)# 修复搜索结果中的编码问题if 'result' in data and 'content' in data['result']:for item in data['result']['content']:if isinstance(item, dict) and 'text' in item:# 尝试修复编码问题text = item['text']if isinstance(text, str):try:# 尝试重新编码item['text'] = text.encode('latin1').decode('utf-8')except (UnicodeDecodeError, UnicodeEncodeError):# 如果编码修复失败,保持原样passreturn datareturn {}except (json.JSONDecodeError, Exception) as e:print(f"SSE解析失败: {e}")return {}def _send_request(self, method: str = 'POST', data: Optional[Dict] = None) -> Dict[str, Any]:"""发送HTTP请求到MCP端点Args:method: HTTP方法 (GET, POST等)data: 请求数据Returns:响应数据字典"""try:# 打印API调用详情print("\n" + "="*60)print("📡 API 调用详情")print("="*60)print(f"🔗 URL: {self.base_url}")print(f"📋 方法: {method}")# 显示请求头headers_to_show = dict(self.session.headers)if self.session_id:headers_to_show['mcp-session-id'] = self.session_idheaders_to_show['X-Session-ID'] = self.session_idprint(f"📤 请求头:")for key, value in headers_to_show.items():if 'token' in key.lower():print(f" {key}: {value[:20]}...{value[-10:]}") # 隐藏部分tokenelse:print(f" {key}: {value}")# 显示请求体if data:print(f"📦 请求体 (JSON):")print(json.dumps(data, indent=2, ensure_ascii=False))else:print(f"📦 请求体: 无")# 如果有会话ID,添加到请求头if self.session_id:self.session.headers['mcp-session-id'] = self.session_idself.session.headers['X-Session-ID'] = self.session_id# 发送请求if method.upper() == 'GET':response = self.session.get(self.base_url)else:response = self.session.post(self.base_url, json=data)# 显示响应详情print(f"\n📥 响应详情:")print(f" 状态码: {response.status_code}")print(f" 响应头:")for key, value in response.headers.items():print(f" {key}: {value}")# 提取会话IDif 'mcp-session-id' in response.headers:self.session_id = response.headers['mcp-session-id']print(f" ✅ 会话ID已更新: {self.session_id}")# 显示原始响应内容print(f"\n📄 原始响应内容:")print(f" 长度: {len(response.text)} 字符")print(f" 前200字符: {response.text[:200]}...")# 解析响应if response.text:# 检查是否是Server-Sent Events格式if 'text/event-stream' in response.headers.get('content-type', ''):parsed_data = self._parse_sse_data(response.text)print(f"\n🔍 解析后的JSON数据:")print(json.dumps(parsed_data, indent=2, ensure_ascii=False))result = {'status': response.status_code,'data': parsed_data,'headers': dict(response.headers)}else:try:json_data = response.json()print(f"\n🔍 解析后的JSON数据:")print(json.dumps(json_data, indent=2, ensure_ascii=False))result = {'status': response.status_code,'data': json_data,'headers': dict(response.headers)}except json.JSONDecodeError:result = {'status': response.status_code,'data': response.text,'headers': dict(response.headers)}else:result = {'status': response.status_code,'data': None,'headers': dict(response.headers)}print("="*60)return resultexcept requests.RequestException as e:print(f"❌ 请求失败: {e}")return {'status': 0, 'data': None, 'error': str(e)}def connect(self) -> bool:"""建立连接并创建会话 - 修复版本Returns:连接是否成功"""print("正在连接到Bright Data MCP服务...")# 尝试GET请求创建会话result = self._send_request('GET')print(f"连接结果: HTTP {result['status']}")print(f"响应内容: {result.get('data', 'None')}")# 如果返回400且提示需要sessionId,直接跳过连接检查,尝试初始化if result['status'] == 400 and result.get('data') == 'No sessionId':print("⚠️ 服务器要求sessionId,跳过连接检查,直接尝试初始化...")return Trueelif result['status'] == 200:print("✅ 连接成功!")return Trueelse:print(f"⚠️ 连接状态异常,但继续尝试: {result.get('data', '未知错误')}")return True # 继续尝试,可能服务器有特殊处理def initialize(self) -> Dict[str, Any]:"""初始化MCP协议连接Returns:初始化结果"""init_message = {"jsonrpc": "2.0","id": self.message_id,"method": "initialize","params": {"protocolVersion": "2024-11-05","capabilities": {"roots": {"listChanged": True},"sampling": {}},"clientInfo": {"name": "Python MCP Client","version": "1.0.0"}}}self.message_id += 1print("正在初始化MCP协议...")result = self._send_request('POST', init_message)print(f"初始化结果: HTTP {result['status']}")if result['status'] == 200 and result['data'] and isinstance(result['data'], dict) and not result['data'].get('error'):# 发送initialized通知notify_message = {"jsonrpc": "2.0","method": "notifications/initialized"}self._send_request('POST', notify_message)print("✅ MCP协议初始化成功!")else:print(f"⚠️ 初始化响应: {result}")return resultdef list_tools(self) -> Dict[str, Any]:"""获取可用工具列表Returns:工具列表"""message = {"jsonrpc": "2.0","id": self.message_id,"method": "tools/list","params": {}}self.message_id += 1print("正在获取工具列表...")result = self._send_request('POST', message)if result['status'] == 200 and result['data']:tools = result['data'].get('result', {}).get('tools', [])print(f"✅ 发现 {len(tools)} 个可用工具:")for tool in tools:print(f" - {tool.get('name', '未知')}: {tool.get('description', '无描述')}")else:print(f"⚠️ 工具列表响应: {result}")return resultdef search(self, query: str, engine: str = "google") -> Dict[str, Any]:"""执行搜索Args:query: 搜索关键词engine: 搜索引擎 (google, bing, yandex)Returns:搜索结果"""message = {"jsonrpc": "2.0","id": self.message_id,"method": "tools/call","params": {"name": "search_engine","arguments": {"query": query,"engine": engine}}}self.message_id += 1print(f"🔍 正在搜索: {query} (使用 {engine})")result = self._send_request('POST', message)if result['status'] == 200 and result['data']:search_results = result['data'].get('result', {}).get('content', [])if search_results:print(f"✅ 找到 {len(search_results)} 个搜索结果\n")# 解析搜索结果for i, item in enumerate(search_results[:5], 1):if isinstance(item, dict):text = item.get('text', '')# 解析Markdown格式的搜索结果lines = text.split('\n')title = ""url = ""description = ""# 提取标题、URL和描述for line in lines:line = line.strip()if not line:continue# 查找标题(通常是第一行或包含#的行)if not title and (line.startswith('#') or len(line) < 100):title = line.replace('#', '').strip()# 查找URL(包含http的行)elif 'http' in line and not url:# 提取URLimport reurl_match = re.search(r'https?://[^\s\)]+', line)if url_match:url = url_match.group()# 查找描述(较长的文本行)elif len(line) > 50 and not line.startswith('http') and not description:description = line[:200] + "..." if len(line) > 200 else line# 显示格式化的搜索结果print(f"🔍 结果 {i}:")if title:print(f" 📌 标题: {title}")if url:print(f" 🔗 链接: {url}")if description:print(f" 📝 描述: {description}")print("-" * 60)else:print(f"📄 结果 {i}: {str(item)[:100]}...")else:print("❌ 未找到搜索结果")else:print(f"⚠️ 搜索响应: {result}")return resultdef scrape(self, url: str) -> Dict[str, Any]:"""抓取网页内容Args:url: 要抓取的网址Returns:抓取结果"""message = {"jsonrpc": "2.0","id": self.message_id,"method": "tools/call","params": {"name": "scrape_as_markdown","arguments": {"url": url}}}self.message_id += 1print(f"🌐 正在抓取网页: {url}")result = self._send_request('POST', message)if result['status'] == 200 and result['data']:content = result['data'].get('result', {}).get('content', [])if content:text_content = ''.join([item.get('text', '') for item in content if isinstance(item, dict)])print(f"✅ 抓取成功,内容长度: {len(text_content)} 字符")print(f"预览: {text_content[:200]}...")else:print("❌ 抓取失败或内容为空")else:print(f"⚠️ 抓取响应: {result}")return result# 使用示例
if __name__ == "__main__":# 使用你的Bright Data tokenTOKEN = "57d1a452149d90e8e10399969cedd1c55871600e0c12ed12ef870b448f9a8c06"# 创建客户端client = MCPClient(TOKEN)print("=== Python MCP客户端测试 (修复版) ===\n")# 1. 连接if client.connect():# 2. 初始化init_result = client.initialize()# 3. 列出工具tools_result = client.list_tools()# 4. 执行搜索print("\n--- 搜索测试 ---")search_result = client.search("Python编程教程")print("\n=== 测试完成 ===")else:print("连接失败,无法继续测试")
4.2.2 interactive_client.py 交互式命令行界面
主要功能:
- 💬 命令行交互 - 提供用户友好的命令行界面
- 🔍 搜索命令 -
search <关键词> [引擎]
- 🌐 抓取命令 -
scrape <网址>
- ℹ️ 帮助系统 - 显示可用命令和使用示例
使用方式:python interactive_client.py
源码:
#!/usr/bin/env python3
"""
交互式Python MCP客户端
支持命令行交互使用
"""from mcp_client_fixed import MCPClient
import sysdef print_help():"""打印帮助信息"""print("""
=== Python MCP客户端交互模式 ===可用命令:search <关键词> - 搜索 (默认使用Google)search <关键词> <引擎> - 指定搜索引擎 (google/bing/yandex)scrape <网址> - 抓取网页内容tools - 列出可用工具help - 显示此帮助quit/exit - 退出程序示例:search Python教程search 人工智能 bingscrape https://www.example.com
""")def main():# 使用你的Bright Data tokenTOKEN = "57d1a452149d90e8e10399969cedd1c55871600e0c12ed12ef870b448f9a8c06"print("🚀 启动Python MCP客户端...")client = MCPClient(TOKEN)# 连接和初始化if not client.connect():print("❌ 连接失败,程序退出")returnclient.initialize()print("✅ 客户端已就绪!")print_help()# 交互循环while True:try:user_input = input("\n>>> ").strip()if not user_input:continueparts = user_input.split()command = parts[0].lower()if command in ['quit', 'exit']:print("👋 再见!")breakelif command == 'help':print_help()elif command == 'tools':client.list_tools()elif command == 'search':if len(parts) < 2:print("❌ 请提供搜索关键词: search <关键词> [引擎]")continuequery = ' '.join(parts[1:-1]) if len(parts) > 2 else ' '.join(parts[1:])engine = parts[-1] if len(parts) > 2 and parts[-1] in ['google', 'bing', 'yandex'] else 'google'if len(parts) > 2 and parts[-1] in ['google', 'bing', 'yandex']:query = ' '.join(parts[1:-1])else:query = ' '.join(parts[1:])engine = 'google'result = client.search(query, engine)# 显示详细结果if result['status'] == 200 and result['data']:search_results = result['data'].get('result', {}).get('content', [])if search_results:print(f"\n📋 搜索结果 ({len(search_results)} 条):")for i, item in enumerate(search_results[:5], 1):if isinstance(item, dict):text = item.get('text', '')lines = text.split('\n')title = lines[0] if lines else text[:100]print(f"\n{i}. {title}")if len(lines) > 1:print(f" {lines[1][:150]}...")elif command == 'scrape':if len(parts) < 2:print("❌ 请提供网址: scrape <网址>")continueurl = parts[1]if not url.startswith(('http://', 'https://')):url = 'https://' + urlresult = client.scrape(url)# 显示抓取结果if result['status'] == 200 and result['data']:content = result['data'].get('result', {}).get('content', [])if content:text_content = ''.join([item.get('text', '') for item in content if isinstance(item, dict)])print(f"\n📄 抓取结果 (共 {len(text_content)} 字符):")print("=" * 50)print(text_content[:1000]) # 显示前1000字符if len(text_content) > 1000:print(f"\n... (还有 {len(text_content) - 1000} 字符)")print("=" * 50)else:print(f"❌ 未知命令: {command}")print("输入 'help' 查看可用命令")except KeyboardInterrupt:print("\n\n👋 程序被中断,再见!")breakexcept Exception as e:print(f"❌ 发生错误: {e}")if __name__ == "__main__":main()
4.2.3 requirements.txt Python依赖文件
requests>=2.25.0
4.2.4 READEM.md 使用文档(补充流程)
# Python MCP客户端这是一个Python版本的MCP (Model Context Protocol) 客户端,用于调用Bright Data的搜索和网页抓取服务。## 📁 文件结构```
python-mcp-client/
├── mcp_client.py # 核心MCP客户端类
├── interactive_client.py # 交互式命令行客户端
├── requirements.txt # Python依赖
└── README.md # 说明文档
```## 🚀 快速开始### 1. 安装依赖
```bash
pip install -r requirements.txt
```### 2. 交互式使用
```bash
python interactive_client.py
```### 3. 编程使用
```python
from mcp_client import MCPClient# 创建客户端
client = MCPClient("你的token")# 连接和初始化
client.connect()
client.initialize()# 搜索
result = client.search("Python教程")# 网页抓取
result = client.scrape("https://www.example.com")
```## 🔧 主要功能### MCPClient类方法- `connect()` - 建立连接
- `initialize()` - 初始化MCP协议
- `list_tools()` - 获取可用工具
- `search(query, engine)` - 执行搜索
- `scrape(url)` - 抓取网页### 交互式命令- `search <关键词>` - 搜索
- `search <关键词> <引擎>` - 指定搜索引擎
- `scrape <网址>` - 抓取网页
- `tools` - 列出工具
- `help` - 帮助
- `quit` - 退出## 🌐 支持的搜索引擎- Google (默认)
- Bing
- Yandex## 📝 使用示例```python
# 搜索示例
client.search("人工智能", "google")
client.search("机器学习", "bing")# 抓取示例
client.scrape("https://www.python.org")
client.scrape("https://github.com")
```## 🔑 Token配置在代码中修改TOKEN变量为你的Bright Data token:
```python
TOKEN = "你的Bright Data token"
4.3 HTTP方式调用MCP API
首先大家要知道,Bright Data MCP提供了两个工具
- ✅ 搜索功能 - 支持Google/Bing/Yandex
- ✅ 网页抓取 - 任意网页转Markdown
# Token使用
self.base_url = f"https://mcp.brightdata.com/mcp?token={token}"# HTTP请求
response = self.session.post(self.base_url, json=data)# 搜索调用
client.search("Python教程", "google")# 抓取调用
client.scrape("https://www.example.com")
咱们的工作流程:
- 初始化 →
MCPClient
创建实例,传入token- 连接 →
connect()
建立连接,获取会话ID- 初始化协议 →
initialize()
初始化MCP协议- 功能调用 →
search()
或scrape()
调用相应功能- 结果处理 → 解析和显示返回结果
使用方式:
cd python-mcp-client
python interactive_client.py
请求体(JSON)
响应结果:
可以将text内容,丢给AI完成资料整理。我们前面两篇都是一样的做法。
通过验证,连接是可以正常访问的,内容应该没有问题的。不过,推荐大家直接拿着JSON配置文件直接调用API得了,Bright Data MCP功能是十分厉害的,然后搭配n8n Web Scraper Integration专门用于网页数据抓取,可以躺着挣大米。
五、总结和分析
Bright Data MCP不仅是一款技术产品,更代表着数据获取领域的革命性飞跃。作为Bright Data团队智慧的结晶,这一模型上下文协议服务器突破了传统网络数据采集的限制,为人工智能时代的信息获取开辟了全新道路。
尽管市场上存在多种MCP服务,Bright Data MCP凭借其独特优势脱颖而出:它能实时获取网络数据,巧妙绕过地理限制,有效突破网站反爬虫机制,同时支持浏览器自动化和系统无缝集成,确保数据的安全性与可靠性。
使用建议与限制说明:
- 前 3 个月免费额度为每月 5,000 次请求,适合开发测试与轻量级应用
- 超出额度或使用高级功能(如 mcp_browser)将产生费用
- 多用户团队共享免费额度
小二诚挚你尝试使用Bright Data MCP,前 3 个月免费额度为每月 5,000 次请求。同时也推荐大家,使用亮数据其他产品。
亮数据注册连接:https://get.brightdata.com/d_mcpserver