简易爬虫平台设计与实现

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

前言

早期,我为了抓取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
相关推荐
Go Dgg4 小时前
Go语言实现豆瓣电影Top250爬虫
开发语言·爬虫·golang
攻城狮7号5 小时前
Python爬虫第20节-使用 Selenium 爬取小米商城空调商品
开发语言·数据库·爬虫·python·selenium
奋斗者1号17 小时前
浏览器自动化与网络爬虫实战:工具对比与选型指南
运维·爬虫·自动化
q567315231 天前
Node.js数据抓取技术实战示例
爬虫·python·scrapy·node.js
.生产的驴1 天前
SpringBoot 集成滑块验证码AJ-Captcha行为验证码 Redis分布式 接口限流 防爬虫
java·spring boot·redis·分布式·后端·爬虫·tomcat
来自星星的坤2 天前
Python 爬虫基础入门教程(超详细)
开发语言·爬虫·python
浩皓素2 天前
Python网络爬虫:从入门到实践
爬虫·python
大河之J天上来2 天前
从爬虫到网络---<基石9> 在VPS上没搞好Docker项目,把他卸载干净
网络·爬虫·docker
小白学大数据2 天前
Python爬虫中time.sleep()与动态加载的配合使用
爬虫·python·scrapy·数据分析
5649833 天前
爬虫学习————开始
爬虫·学习