简易爬虫平台设计与实现

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

前言

早期,我为了抓取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
相关推荐
深蓝电商API1 天前
0 基础入门爬虫:Python+requests 环境搭建保姆级教程
开发语言·爬虫·python
B站计算机毕业设计之家2 天前
基于Python+Django+双协同过滤豆瓣电影推荐系统 协同过滤推荐算法 爬虫 大数据毕业设计(源码+文档)✅
大数据·爬虫·python·机器学习·数据分析·django·推荐算法
孤狼warrior2 天前
目前最新同花顺金融股市数据爬取 JS逆向+node.js补浏览器环境
javascript·爬虫·python·金融·node.js
xiaoxiongip6662 天前
假设两个设备在不同网段,网关怎么设置才能通呢
网络·爬虫·python·https·智能路由器
tryCbest2 天前
Python基础之爬虫技术(一)
开发语言·爬虫·python
疏狂难除2 天前
某个网址的爬虫——mitmproxy的简单使用
爬虫·mitmproxy
想要打 Acm 的小周同学呀2 天前
爬虫相关的面试问题
爬虫·selenium·职场和发展
QMY5205202 天前
爬虫技术抓取网站数据的方法
运维·爬虫·自动化
傻啦嘿哟3 天前
房地产爬虫实战:链家二手房数据抓取与深度分析
爬虫
雨中散步撒哈拉3 天前
16、做中学 | 初三上期 Golang面向对象_进阶
爬虫·python·golang