简易爬虫平台设计与实现

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

前言

早期,我为了抓取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
相关推荐
xiaoxiongip66618 小时前
动态ip适合挂什么项目
网络·爬虫·python·网络协议·tcp/ip·ip
q567315231 天前
自动化拨号爬虫体系:虚拟机集群部署与增量管理
运维·爬虫·网络协议·自动化
电商API_180079052472 天前
淘宝商品视频批量自动化获取的常见渠道分享
java·爬虫·自动化·网络爬虫·音视频
果壳~2 天前
【Python】爬虫html提取内容基础,bs4
爬虫·python·html
jay神2 天前
基于Python的商品爬取与可视化系统
爬虫·python·数据分析·毕业设计·可视化系统
华科云商xiao徐3 天前
如何在C语言环境中借助Linux库构建高效网络爬虫
爬虫·数据挖掘·数据分析
明远湖之鱼3 天前
巧用 Puppeteer + Cheerio:批量生成高质量 Emoji 图片
前端·爬虫·node.js
爬虫程序猿3 天前
《京东商品详情爬取实战指南》
爬虫·python
ningmengjing_3 天前
webpack打包方式
前端·爬虫·webpack·node.js·逆向
小白学大数据3 天前
构建企业级Selenium爬虫:基于隧道代理的IP管理架构
爬虫·tcp/ip·selenium