简易爬虫平台设计与实现

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

前言

早期,我为了抓取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
相关推荐
kunge1v511 小时前
学习爬虫第四天:多任务爬虫
爬虫·python·学习·beautifulsoup
你也渴望鸡哥的力量么21 小时前
爬虫学习笔记
笔记·爬虫·学习
深蓝电商API1 天前
常见反爬虫策略与破解方案汇总
爬虫
(时光煮雨)2 天前
【Python进阶】Python爬虫-Selenium
爬虫·python·selenium
嫂子的姐夫2 天前
10-七麦js扣代码
前端·javascript·爬虫·python·node.js·网络爬虫
深蓝电商API2 天前
将爬虫部署到服务器:Scrapy+Scrapyd 实现定时任务与监控
服务器·爬虫·scrapy
nightunderblackcat2 天前
四大名著智能可视化推演平台
前端·网络·爬虫·python·状态模式
数据牧羊人的成长笔记2 天前
python爬虫scrapy框架使用
爬虫·python·scrapy
Fairy_sevenseven3 天前
[1]python爬虫入门,爬取豆瓣电影top250实践
开发语言·爬虫·python
white-persist3 天前
MCP协议深度解析:AI时代的通用连接器
网络·人工智能·windows·爬虫·python·自动化