Skip to content
Back to search

FNewsCrawler

一个专门为大模型设计的财经信息MCP(Model Context Protocol)服务,通过高效的爬虫技术从各大财经网站(同花顺、东方财富等)获取实时资讯,为AI模型提供准确、及时的财经数据支持。

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/noimank--fnewscrawler/badge.svg)](/listings/noimank--fnewscrawler)

HTML

<a href="/listings/noimank--fnewscrawler"><img src="/api/listings/noimank--fnewscrawler/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 372 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. # FNewsCrawler (该项目已放弃维护)
  2. ## 由于架构设计不合理,后期维护极其复杂,现在已经放弃维护,请转向新项目:https://github.com/noimank/OmniData
  3. [![Python](https://img.shields.io/badge/Python-3.8+-blue.svg)](https://www.python.org/downloads/)
  4. [![FastAPI](https://img.shields.io/badge/FastAPI-0.100+-green.svg)](https://fastapi.tiangolo.com/)
  5. [![MCP](https://img.shields.io/badge/MCP-Compatible-orange.svg)](https://modelcontextprotocol.io/)
  6. [![License](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
  7. **专业的财经信息MCP服务** - 为大模型提供实时、准确的财经资讯数据
  8. ## 🚀 项目简介
  9. FNewsCrawler 是一个专门为大模型设计的财经信息MCP(Model Context Protocol)服务,通过高效的爬虫技术从各大财经网站获取实时资讯,为AI模型提供准确、及时的财经数据支持。
  10. ### 🎯 核心特性
  11. - **🤖 MCP协议兼容**:完全兼容Model Context Protocol,可无缝集成到各种AI应用中
  12. - **📈 实时财经数据**:支持从同花顺问财等主流财经平台获取最新资讯
  13. - **🏗️ 企业级架构**:采用单例模式的浏览器管理和上下文共享机制
  14. - **🔐 智能登录系统**:支持二维码登录,自动维护登录状态
  15. - **⚡ 高性能并发**:基于异步架构,支持高并发访问
  16. - **🛡️ 生产级稳定性**:完善的错误处理、自动重试和健康检查机制
  17. - **📊 可视化管理**:提供Web界面进行工具管理和系统监控
  18. ![img.png](public/img.png)
  19. ## 🏛️ 系统架构
  20. ```
  21. FNewsCrawler
  22. ├── 🧠 MCP服务层 # 为大模型提供标准化接口
  23. ├── 🕷️ 爬虫引擎层 # 多站点财经数据采集
  24. ├── 🌐 浏览器管理层 # 单例浏览器实例管理
  25. ├── 🔄 上下文共享层 # 域名级别的会话状态管理
  26. ├── 🔐 登录认证层 # 二维码登录和状态维护
  27. └── 💾 数据存储层 # Redis缓存和状态持久化
  28. ```
  29. ## 📦 快速开始
  30. ### 环境要求
  31. - Python 3.12+
  32. - Redis 服务器
  33. - Chrome/Chromium 浏览器
  34. ### 安装部署
  35. #### 🐳 Docker部署(推荐)
  36. **方式一:从项目源码部署**
  37. ```bash
  38. # 克隆项目
  39. git clone https://github.com/noimank/FNewsCrawler.git
  40. cd FNewsCrawler
  41. # 构建并启动服务
  42. docker-compose up -d
  43. # 查看服务状态
  44. docker-compose ps
  45. # 查看日志
  46. docker-compose logs -f
  47. ```
  48. **方式二:快速部署启动**
  49. ```bash
  50. #从dockerhub中拉取镜像并后台启动
  51. docker run --name fnewscrawler -p 8480:8480 -d noimankdocker/fnewscrawler:latest
  52. # 查看日志
  53. docker logs fnewscrawler -f
  54. ```
  55. > 📚 **详细文档**:查看 [Docker部署指南](docker/README.md) 了解完整的部署选项、配置说明和故障排除方法。
  56. #### 📦 本地开发测试
  57. 1. **克隆项目**
  58. ```bash
  59. git clone https://github.com/noimank/FNewsCrawler.git
  60. cd FNewsCrawler
  61. ```
  62. 2. **安装依赖**
  63. ```bash
  64. uv sync
  65. uv run playwright install chromium
  66. ```
  67. 3. **配置环境**
  68. ```bash
  69. # 创建 .env 文件,配置环境变量,建议关闭无头模式进行
  70. cp .env.example .env
  71. ```
  72. 4. **启动Redis服务**
  73. ```bash
  74. # Ubuntu/Debian
  75. sudo systemctl start redis-server
  76. # macOS
  77. brew services start redis
  78. # Windows
  79. # 下载并启动Redis服务
  80. ```
  81. 5. **启动服务**
  82. ```bash
  83. # 启动Web服务
  84. uv run python main.py
  85. ```
  86. ### MCP客户端集成
  87. MCP访问协议支持sse和http,通过环境变量MCP_SERVER_TYPE修改
  88. mcp服务地址:http://localhost:8480/mcp/mcp-server
  89. cherryStudio配置:
  90. ```
  91. {
  92. "mcpServers": {
  93. "fnewscrawler": {
  94. "url": "http://localhost:8480/mcp/mcp-server",
  95. "type": "streamableHttp"
  96. }
  97. }
  98. }
  99. ```
  100. ### get方法调用
  101. 调用端点:http://localhost:8480/api/mcp/call_tool/{tool_name}?xxxx
  102. 参数:
  103. - tool_name:工具名称
  104. - xxxx:工具参数
  105. 返回:
  106. - 工具执行结果,json格式
  107. 示例:
  108. ```
  109. GET http://localhost:8480/api/mcp/call_tool/get_industry_stock_funds_flow_tool?industry_name=银行
  110. ```
  111. 如果参数类型为list,需要用逗号分隔
  112. 示例:
  113. ```
  114. GET http://localhost:8480/api/mcp/call_tool/news_crawl_batch?urls=http://example.com,http://example2.com
  115. ```
  116. 额外支持的功能:调用任意的akshare函数
  117. 调用端点:http://localhost:8480/api/mcp/call_akshare/{fun_name}?xxxx
  118. 参数:
  119. - fun_name:函数名称
  120. - xxxx:函数参数
  121. 支持对返回结果进行处理:
  122. - duplicate_key:去重字段
  123. - drop_columns:删除字段,多个字段用逗号分隔
  124. - return_type:返回类型,markdown或json,默认markdown
  125. - filter_condition:筛选条件字符串,类似于sql语法,采用pandas的query语句实现,参考:https://gairuo.com/p/pandas-query
  126. - limit:返回数据条数限制,默认不限制
  127. - sort_by:排序字段,指定按哪一列进行排序
  128. - ascending:排序方式,true为升序,false为降序,默认true
  129. 返回:
  130. - 函数执行结果,json格式,结果格式如下:
  131. ```json
  132. {
  133. "success": true,
  134. "message": "调用工具 stock_zh_a_gbjg_em 成功",
  135. "data": {
  136. "result": xxxxx函数执行结果,markdown格式就是字符串,json格式就是list[str]xxxx
  137. }
  138. }
  139. ```
  140. 示例:
  141. ```
  142. GET http://localhost:8480/api/mcp/call_akshare/stock_zh_a_gbjg_em?symbol=603392.SH&return_type=json
  143. GET http://localhost:8480/api/mcp/call_akshare/stock_zh_a_gbjg_em?duplicate_key=变更日期&drop_columns=流通受限股份,变动原因&return_type=json&symbol=603392.SH
  144. GET http://localhost:8480/api/mcp/call_akshare/news_trade_notify_dividend_baidu?return_type=json&date=20240409&filter_condition=交易所 == "SZ"
  145. # 排序和限制示例
  146. GET http://localhost:8480/api/mcp/call_akshare/stock_zh_a_hist?symbol=000001&sort_by=日期&ascending=true&limit=10
  147. GET http://localhost:8480/api/mcp/call_akshare/stock_zh_a_hist?symbol=000001&sort_by=收盘&ascending=false&limit=5&return_type=json
  148. GET http://localhost:8480/api/mcp/call_akshare/stock_zh_a_hist?symbol=000001&filter_condition=收盘 > 10&sort_by=成交量&ascending=false&limit=3&drop_columns=变动因素
  149. ```
  150. 错误示例:
  151. ```
  152. GET http://localhost:8480/api/mcp/call_akshare/stock_zh_a_gbjg_em?symbol="603392.SH"&return_type=json
  153. ```
  154. **注意事项:**
  155. - 不要给参数加上引号,单引号双引号都不要加,filter_condition除外
  156. - sort_by字段必须是返回数据中的实际列名
  157. - limit必须是正整数,ascending支持true/false、1/0、yes/no等格式
  158. > 📚 **详细文档**:查看 [GET API 接口文档](docs/get_api.md) 了解完整的接口说明、参数配置和使用示例。
  159. ## 🛠️ 功能开发路线图
  160. ### 🔄 已完成
  161. - [x] 同花顺问财新闻资讯查询接口
  162. - [x] MCP协议标准支持
  163. - [x] 同花顺行业资金流向查询接口
  164. - [x] 同花顺概念资金流向查询接口
  165. - [x] 通用新闻查询接口
  166. - [x] 同花顺财经要闻、宏观经济、产经新闻、国际财经、金融市场、公司新闻、区域经济、财经评论、财经人物查询接口
  167. - [x] 同花顺问财A股股票语义筛选工具
  168. - [x] 同花顺问财融资融券信息查询工具
  169. - [x] 同花顺问财历史资金流向查询工具
  170. - [x] 东方财富某行业历史资金流查询工具
  171. - [x] 东方财富某行业个股历史资金流查询工具
  172. - [x] 东方财富大盘资金流查询工具
  173. - [x] 东方财富股票大宗交易每日明细查询工具
  174. - [x] 东方财富股票龙虎榜查询工具
  175. - [x] tushare数据源支持
  176. - [x] 股票技术指标查询接口
  177. - 移动平均线
  178. - 布林带
  179. - KDJ
  180. - MACD
  181. - RSI
  182. - VWMA
  183. - ATR
  184. - [x] 股票筹码及胜率查询接口(tushare)
  185. - [x] 股票筹码分布查询接口(akshare)
  186. - [x] 接入akshare数据源
  187. - [x] 提供get端点调用任意akshare函数
  188. - [x] 北向/南向资金流向
  189. ### 📈 即将推出
  190. - [ ] 龙虎榜数据接口
  191. - 机构交易明细
  192. - 营业部排名分析
  193. - [ ] 行情中心接口
  194. - 实时行情推送
  195. - 盘口数据分析
  196. tips:
  197. 大部分接口如果没有做成mcp接口的话,可以通过get方法调用akshare函数实现。
  198. ### 🎯 长期规划
  199. - [ ] 扩展更多财经数据源
  200. - [ ] 提供完整的API文档
  201. - [ ] 高级数据分析工具
  202. 目标是构建一个全方位的财经信息MCP服务,为大模型提供实时、准确的财经资讯数据。
  203. ## 🔧 开发指南
  204. ### 添加新的财经数据源
  205. 1. **创建爬虫模块**
  206. ```bash
  207. mkdir fnewscrawler/spiders/新站点名
  208. touch fnewscrawler/spiders/新站点名/__init__.py
  209. touch fnewscrawler/spiders/新站点名/crawl.py
  210. touch fnewscrawler/spiders/新站点名/login.py # 如需登录
  211. ```
  212. 2. **实现登录类**(如需要)
  213. ```python
  214. from fnewscrawler.core.qr_login_base import QRLoginBase
  215. class NewSiteLogin(QRLoginBase):
  216. async def get_qr_code(self, qr_type: str) -> Tuple[bool, str]:
  217. # 实现二维码获取逻辑
  218. pass
  219. async def verify_login_success(self) -> bool:
  220. # 实现登录验证逻辑
  221. pass
  222. ```
  223. 3. **创建MCP工具**
  224. ```python
  225. # fnewscrawler/mcp/新站点名/crawl.py
  226. from fnewscrawler.mcp import mcp_server
  227. @mcp_server.tool()
  228. async def new_site_query(query: str):
  229. """新站点查询工具描述"""
  230. # 实现查询逻辑
  231. pass
  232. ```
  233. 4. **注册工具**
  234. ```python
  235. # fnewscrawler/mcp/新站点名/__init__.py
  236. import fnewscrawler.mcp.新站点名.crawl
  237. ```
  238. ### 核心设计原则
  239. - **单例模式**:BrowserManager和ContextManager采用单例模式,确保资源高效利用
  240. - **域名隔离**:每个域名维护独立的浏览器上下文,避免会话冲突
  241. - **异步优先**:全面采用异步编程,提升并发性能
  242. - **状态持久化**:登录状态和会话信息自动保存到Redis
  243. - **健康检查**:定期检查浏览器和上下文健康状态,自动恢复异常
  244. ## 📊 系统监控
  245. 访问 `http://localhost:8480/monitor` 查看系统状态:
  246. - 🌐 **浏览器状态**:实例健康度、版本信息、资源使用
  247. - 🔄 **上下文管理**:活跃会话、空闲时间、使用统计
  248. - 🛠️ **MCP工具**:工具状态、启用/禁用管理
  249. - 📈 **系统日志**:实时日志查看和过滤
  250. ## 🔧 工具管理
  251. 访问 `http://localhost:8480/mcp` 进行工具管理:
  252. - ✅ **启用/禁用工具**:动态控制工具可用性
  253. - 📝 **工具详情查看**:查看工具描述和参数
  254. - 🔄 **批量操作**:支持批量启用/禁用工具
  255. - 📊 **使用统计**:工具调用次数和状态监控
  256. ## 🤝 贡献指南
  257. 我们欢迎社区贡献!请查看 [开发文档](docs/) 了解详细信息:
  258. - [爬虫开发指南](docs/spider_development.md)
  259. - [MCP工具开发指南](docs/mcp_tool_development.md)
  260. ## 📄 许可证
  261. 本项目采用 MIT 许可证 - 查看 [LICENSE](LICENSE) 文件了解详情。
  262. ## 🙏 致谢
  263. - [FastMCP](https://github.com/jlowin/fastmcp) - MCP协议实现
  264. - [Playwright](https://playwright.dev/) - 浏览器自动化
  265. - [FastAPI](https://fastapi.tiangolo.com/) - Web框架
  266. - [Redis](https://redis.io/) - 数据存储
  267. ---
  268. **为大模型提供专业的财经数据支持** 🚀
  269. 如有问题或建议,请提交 [Issue](https://github.com/noimank/FNewsCrawler/issues) 或 [Pull Request](https://github.com/noimank/FNewsCrawler/pulls)。

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.