简易爬虫平台设计与实现

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

前言

早期,我为了抓取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
相关推荐
java1234_小锋13 小时前
[免费]基于Python的天气预报(天气预测分析)(Django+sklearn机器学习+selenium爬虫)可视化系统【论文+源码+SQL脚本】
爬虫·python·selenium·天气预报·天气预测
38242782713 小时前
python3网络爬虫开发实战 第2版:使用aiohttp
开发语言·爬虫·python
APIshop14 小时前
API 接口文档测试:从“能跑”到“敢上线”的完整闭环
爬虫·python
盼哥PyAI实验室14 小时前
[特殊字符]️ 实战爬虫:Python 抓取【采购公告】接口数据(含踩坑解析)
开发语言·爬虫·python
小白学大数据16 小时前
Python 网络爬虫:Scrapy 解析汽车之家报价与评测
开发语言·爬虫·python·scrapy
weixin_4462608516 小时前
[特殊字符] MediaCrawler - 自媒体平台爬虫 [特殊字符]️
爬虫·媒体
傻啦嘿哟16 小时前
用Kubernetes管理大规模爬虫节点:从单机到云原生的进化之路
爬虫·云原生·kubernetes
王同学_1161 天前
爬虫辅助技术(css选择器、xpath、正则基础语法)
前端·css·爬虫
3824278272 天前
使用 webdriver-manager配置geckodriver
java·开发语言·数据库·爬虫·python