centos7部署pyspider
一、 安装依赖
yum install gcc gcc-c++ python-pip python-devel python-distribute libxml2 libxml2-devel python-lxml libxslt libxslt-devel openssl openssl-devel
二、脚本安装和升级pip(已安装pip可忽略)
运行以下命令 (需要管理员权限):
wget https://bootstrap.pypa.io/get-pip.py
$ python get-pip.py
$ pip -V #查看pip版本
三 、pip安装pyspider
pip install pyspider
Error: You should consider upgrading via the 'pip install --upgrade pip' command.
pip install --upgrade pip #升级pip即可
Error: Command "python setup.py egg_info" failed with error code 1 in
pip3 install pyspider #python2.7以下无pycul
Error:ImportError: pycurl: libcurl link-time version (7.19.7) is older than compile-time version (7.43.0)
移步:https://my.oschina.net/crazyharry/blog/341718
可以安装最新pyspider:
https://github.com/binux/pyspider
四 、安装mysql-connector、redis、pymongo、six
pip install mysql-connector
pip install redis
pip install pymongo
pip install six
五 、编辑pyspider 启动文件
本文以mongo为例,数据库并非本地服务,config.json为pyspider的启动文件,配置自定
义数据库,webui为页面登录验证。
{
"taskdb": "mongodb+taskdb://192.168.2.68:27017/pyspider_taskdb",
"projectdb": "mongodb+projectdb://192.168.2.68:27017/pyspider_projectdb",
"resultdb": "mongodb+resultdb://192.168.2.68:27017/pyspider_resultdb",
"message_queue": "redis://192.168.2.100:6379/0",
"webui": {
"username": "username",
"password": "password",
"need-auth": true,
"port": 5000
}
}
六 、启动 pyspider配置文件
pyspider -c /etc/pyspider/config.json #默认启动所有组件
/usr/lib/python2.7/site-packages/pyspider #源码路径
#也可以设置环境变量
vim .bashrc
alias py='pyspider -c /etc/pyspider/config.json'
source ~/.bashrc
#退出保存后执行 source ~/.bashrc 使刚才的配置永久生效了。
七 、尽情的爬取
http://192.168.2.68:5000 #结果默认返回config.json配置的数据库
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)