Centos7 模拟是python2, 需要升级为python3 或者建立虚拟环境,这里不再赘述。
由于scrapydweb 会用到sqlite3, 而普通版本安装的python3 是无法使用sqlite3的,因此需要编译安装python。
python 验证方法:
import sqlite3
如果报错,说明需要重新安装python.
参照:
https://blog.youkuaiyun.com/zd147896325/article/details/80092563
python安装完成后,可以进行其他包的安装。
- 修改pip源为国内源
mkdir ~/.pip
cd ~/.pip
touch pip.conf
pip.conf的内容是:
[global]
index-url=https://pypi.tuna.tsinghua.edu.cn/simple
timeout = 6000
[install]
trusted-host=pypi.tuna.tsinghua.edu.cn
disable-pip-version-check = true
把源更改为清华源。
- 创建scrapy项目
pip install scrapy scrapyd scrapydweb logparser scrapyd-client
scrapy startproject sohu_prj
cd sohu_prj
scrapy genspider sohu sohu.com
修改scrapy.cfg配置:
-
修改scrapyd的配置文件
编辑 /etc/scrapyd/scrapyd.conf 把 bind_address为绑定ip,修改成0.0.0.0,其它主机就可以访问了。
-
启动scrapyd
可以通过浏览器访问 ip:6800 查看页面
-
部署项目到scrapyd
执行命令:
[root@centos7 sohu_prj]# scrapyd-deploy sohu -p sohu_prj
Packing version 1594688864
Deploying to project "sohu_prj" in http://localhost:6800/addversion.json
Server response (200):
{"status": "ok", "project": "sohu_prj", "version": "1594688864", "spiders": 1, "node_name": "centos7"}
-
启动scrapydweb
直接运行scrapydweb, 会在当前目录下生成一个配置文件,需要修改其中的server地址和用户名密码配置。
配置完毕,可以再次启动。
通过 http://ip:5000即可访问。
https://blog.youkuaiyun.com/u013992330/article/details/94994037
https://blog.youkuaiyun.com/bingshi8956/article/details/100958281
https://www.jianshu.com/p/ddd28f8b47fb
https://www.cnblogs.com/asminfo/p/12763656.html
https://blog.youkuaiyun.com/haoxun03/article/details/104149882