简易爬虫平台设计与实现

世界上本没有架构,写的代码多了,就有了架构。

前言

早期,我为了抓取mp3和一些网站文章,随意写了些零零星星的代码。后来,使用了scrapy和webmagic等爬虫框架,算是走上了正轨。又后来,东一个组件,西一个库,东拼西凑,软件又慢慢脱离正轨。到了现在,终于活成了自己的模样,变成了四不像。

整体架构

基本逻辑如下:

  • 通过web端管理爬虫平台,通过手机做一些内容管理,搜索
  • API网关统一接收请求,然后扔到消息队列
  • robot server接收到消息后,远程调用chrome,打开相应页面
  • chrome中内容被mitmproxy截获,mitmproxy再交给一个个Processor处理
  • Processor获得匹配到的内容,完成入库

实现

主要进程

python 复制代码
async def run(args):
    # configure_loguru(args.host, args.port)
    robot_manager = RobotManager()
    robot_manager.load_robots()

    loop = asyncio.get_event_loop()
    tasks = []

    # 启动API网关
    if args.mode == 'gateway':
        tasks.append(launchFastAPIServer())

    # 启动mitm
    if args.mode == 'mitm':
        tasks.append(launch_mitmweb(robot_manager, args))

    # 启动robot server
    if args.mode == 'server':
        tasks.append(launch_robot(robot_manager))

Chrome节点

运行Chrome:

bash 复制代码
chrome --no-sandbox --disable-setuid-sandbox \
       --no-default-browser-check --no-first-run \
       --disable-dev-shm-usage --remote-debugging-port=9222 \
       --user-data-dir=/home/user1/data --proxy-server=http://127.0.0.1:1080
相关推荐
跨境数据猎手9 小时前
跨境商城反向海淘系统开发全流程逻辑(上)
人工智能·爬虫·系统架构
上海云盾-小余10 小时前
网站恶意爬虫拦截策略:智能识别与封禁实操方案
网络·爬虫·安全·web安全
小白学大数据13 小时前
Scrapling:极简高效的 Python 智能爬虫框架
开发语言·爬虫·python·数据分析
深蓝电商API15 小时前
爬虫任务调度系统:基于Celery的定时+触发式采集方案
爬虫
WL_Aurora18 小时前
Python爬虫实战(七):Selenium自动化采集苏宁易购商品数据
爬虫·python·selenium
Python私教1 天前
Playwright MCP 用 a11y 树抓页面:比全量 DOM 省 token 的采集 Agent
爬虫
枫叶林FYL1 天前
项目九:异步高性能爬虫与数据采集中枢 —— 基于 Crawl<sub>4</sub>AI 与 Playwright 的现代化数据采集平台 项目总览
爬虫·python·深度学习·wpf
上海云盾-小余2 天前
恶意爬虫精准拦截:网站流量净化与资源守护方案
网络·爬虫·web安全
小白学大数据2 天前
深度探索:Python 爬虫实现豆瓣音乐全站采集
开发语言·爬虫·python·数据分析
烟雨江南aabb2 天前
Python第六弹:python爬虫篇:什么是爬虫
开发语言·爬虫·python