Python环境的安装:
1、安装依赖环境yum install gccyum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
2、下载Python3.6或其他
①新建个/usr/download 文件夹mkdir /usr/download
②在download文件夹下下载安装包(/usr/download )wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz
③ 解压文件tar -xvf Python-3.6.4.tgz
3、安装Python3
创建安装文件的路径mkdir /usr/local/python3
4、编译(在解压的文件夹下 /usr/download/python3.6.4)./configure --prefix=/usr/local/python3
5、安装(在解压的文件夹下 /usr/download/python3.6.4)makemake install
6、创建新版本的软链接
①修改旧版本mv /usr/bin/python /usr/bin/python_bak
②创建新的软连接ln -s /usr/local/python3/bin/python3 /usr/bin/python3ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
③检查python的版本python -V
7、配置成功后,pip3用不了,需要进一步配置
①将/usr/local/python3/bin加入PATHvim ~/.bash_profile
修改后如下:# .bash_profile# Get the aliases and functionsif[ -f ~/.bashrc ]; then. ~/.bashrcfi# User specific environment and startup programsPATH=$PATH:$HOME/bin:/usr/local/python3/binexport PATH
②保存退出后,执行以下命令,让上一步修改成功source ~/.bash_profile
8.后台运行程序,2>&1标准输出与错误输出nohup python -u run.py > tes.log 2>&1 & # 后台运行程序
Chrome浏览器安装:
1.直接yum安装,一般都能直接装上;或手动下载rpm包yum install https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpmrpm -ivh google-chrome-stable_current_x86_64.rpm
2.查看版本google-chrome-stable -version
3.下载对应版本,Chrome下载地址:http://chromedriver.storage.googleapis.com/index.html
4.安装解压缩工具:yum install unzip
5.解压缩chromedriver:unzip Chromedriver
6.建立软连接ln -s /opt/google/chromedriver /usr/bin/chromedriver
7.改变权限chmod +x /usr/bin/chromedriver
服务器上运行selenium避免出现报错的一些相关配置:options = webdriver.ChromeOptions()options.add_argument('--disable-gpu') # 关闭图形模式options.add_argument('--log-level=2') # 设置日志等级为warningoptions.add_argument('--disable-dev-shm-usage') # 解决服务器报错google-chrome is no longer runningoptions.add_argument('--no-sandbox') # 启用沙盒模式