简易爬虫平台设计与实现

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

前言

早期,我为了抓取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
相关推荐
深蓝电商API2 小时前
用向量数据库存储爬取内容:语义检索的高级玩法
爬虫·向量数据库
深蓝电商API3 小时前
Playwright+多模态大模型:让AI自己“看”页面并决策
人工智能·爬虫·playwright
远航计算机4 小时前
收录从分钟级变 3 到 7 天,抢首发为什么失效了
大数据·人工智能·爬虫·chatgpt·aigc·1024程序员节
嫂子的姐夫1 天前
052-滑块验证码:丰巢登录
爬虫·js逆向·滑块验证码·aes加密
东鹏特饮1 天前
A 股创历史新低筛选器phthon爬虫脚本
爬虫·股票·phthon
深蓝电商API4 天前
用GPT-4o解析无结构网页:提示词工程实战
爬虫·gpt-4o
数据狐(Datafox)4 天前
一文读懂京东商品详情 API:返回字段解读与 JSON 样例
开发语言·数据库·爬虫·json
傻啦嘿哟4 天前
百度图片爬虫:爬取海量图片数据,搭建图像识别训练集
爬虫·百度
SEO_juper4 天前
AI 爬虫 robots.txt 检查工具:你的站是不是把 AI 挡在门外了
开发语言·人工智能·爬虫·python·外贸独立站
OnlineProxy4 天前
Python 高负载异步爬虫优化指南:深挖 httpx 与 aiohttp 的性能极限
爬虫·python·httpx