美文网首页
gerapy 部署scrapy分布式爬虫项目

gerapy 部署scrapy分布式爬虫项目

作者: 厦门第一帅哥 | 来源:发表于2023-08-15 15:37 被阅读0次

    1.安装gerapy

    pip3 install gerapy
    

    2.初始化项目

    # 新建一个文件夹。gerapy-demo。进入文件夹中执行命令
    gerapy init 
    # 初始化数据库
    gerapy migrate
    # 创建用户,根据提示创建
    gerapy createsuperuser
    # 启动服务
    gerapy runserver 
    # 这样服务就运行在http://127.0.0.1:8000/#/
    

    3. 安装scrapyd

    pip3 install scrapyd
    pip3 install scrapyd-cllient
    

    4. 启动scrapyd

    scrapyd 
    

    启动后可以看到scrapyd运行在http://127.0.0.1:6800/
    如果要在阿里云服务器上以守护进程启动scrapyd,命令是nohup scrapyd > scrapyd.log 2>&1 &

    5. 部署爬虫项目

    进入我们的scrapy爬虫项目目录下,修改scrapy.cfg文件,在deploy后面冒号加上自己的部署名,把url的注释放开,project为自己的项目名

    [settings]
    default = football.settings
    
    [deploy:部署名]
    url = http://localhost:6800/
    project = 项目名
    
    # 执行部署项目,部署后会出现一个build文件夹
    scrapyd-deploy 部署名 -p 项目名
    # 运行爬虫
    curl http://localhost:6800/schedule.json -d project=项目名 -d spider=要运行的爬虫名
    # 运行后可以在scrapyd的webui界面看到运行的爬虫情况
    

    相关文章

      网友评论

          本文标题:gerapy 部署scrapy分布式爬虫项目

          本文链接:https://www.haomeiwen.com/subject/bndhmdtx.html