【docker】CentOS6.8+Python2.7+selenium+Firefox的搭建

当前Docker容器配置:

  • Centos6.8
  • python2.6.6

目标Docker容器配置:

  • Centos6.8
  • python2.7
  • selenium 3.141.0
  • geckodriver 0.15
  • firefox 52.8.0
  • Pillow 6.1.0
  • pytesseract 0.2.7

安装依赖环境

yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel libffi-devel gcc make wget git unzip gcc gcc-c++ libjpeg-devel libpng-devel libgif-devel

创建目录存放安装包

 mkdir /usr/local/download
 cd /usr/local/download

安装Python2.7

# 安装python2.7
wget https://www.python.org/ftp/python/2.7.15/Python-2.7.15.tgz
tar -zxvf Python-2.7.15.tgz
cd Python-2.7.15
./configure
make && make install
mv /usr/bin/python /usr/bin/python_bak
ln -s /usr/local/bin/python2.7 /usr/bin/python

# 安装pip
wget --no-check-certificate https://bootstrap.pypa.io/get-pip.py
python get-pip.py
ln -s /usr/local/bin/pip /usr/bin/pip

# 配置pip源(豆瓣)
cd
mkdir .pip
cd .pip
vi pip.conf
#写入如下内容:
[global]
index-url=http://pypi.douban.com/simple
trusted-host = pypi.douban.com 

安装tesseract

# 先安装leptonica
cd /usr/local/download
wget http://www.leptonica.org/source/leptonica-1.72.tar.gz
tar xvzf leptonica-1.72.tar.gz
cd leptonica-1.72/
./configure
make && make install

# 安装tesseract
cd /usr/local/download
wget https://github.com/tesseract-ocr/tesseract/archive/3.04.zip
unzip 3.04.zip
cd tesseract-3.04/
./configure
make && make install
# 手动更新动态链接库
ldconfig
# pip安装pytesseract
pip install pytesseract
# 安装语言包
在https://github.com/tesseract-ocr/tessdata 下载对应语言的模型文件
由于目前只需要识别手机号码和英文,只下载一个eng.traineddata文件即可,
将模型文件移动到/usr/local/share/tessdata
然后即可进行识别

# 示例
import pytesseract
from PIL import Image

image = Image.open('bb.png')
code = pytesseract.image_to_string(image)
print(code)

安装selenium+firefox+geckodriver

安装selenium

pip install selenium

# 查看版本
pip show selenium

安装geckodriver

cd /usr/local/download
wget https://github.com/mozilla/geckodriver/releases/download/v0.15.0/geckodriver-v0.15.0-linux64.tar.gz
tar xvzf geckodriver-*.tar.gz
rm -f /usr/bin/geckodriver
# 软链接必须用绝对路径
ln -s /usr/local/download/geckodriver /usr/bin/geckodriver  

安装firefox

cd /usr/local/download
wget http://www.rpmfind.net/linux/centos/6.10/os/x86_64/Packages/firefox-52.8.0-1.el6.centos.x86_64.rpm
yum install -y firefox-52.8.0-1.el6.centos.x86_64.rpm

安装中文字体

# 新建字体目录 chinese:
mkdir /usr/share/fonts/chinese

# 将windows系统盘 c:\windows\fonts\中的字体直接上传至 centos 的 /usr/share/fonts/chinese目录下即可
chmod -R 755 /usr/share/fonts/chinese
yum -y install ttmkfdir
ttmkfdir -e /usr/share/X11/fonts/encodings/encodings.dir

# 修改fonts.conf的Font directory list,即字体列表,在这里需要把我们添加的中文字体位置加进去:
vi /etc/fonts/fonts.conf
<dir>/usr/share/fonts/chinese</dir>

# 刷新内存中的字体缓存,这样就不用reboot重启了:
fc-cache

# 最后再次通过fc-list看一下字体列表:
fc-list

安装 xvfb

在Linux中有1个很好用的工具xvfb,它是1个X服务可以用于在没有显示器的硬件和物理输入设备上运行

a,安装必需的软件包
[[email protected] ~]# yum install -y xdg-utils xorg-x11-server-Xvfb xorg-x11-xkb-utils

a,安装xvfb的绑定
[[email protected] ~]# pip install xvfbwrapper pyvirtualdisplay

测试用例:

#!/usr/bin/python
# -*- coding:utf-8 -*-
from selenium import webdriver
from pyvirtualdisplay import Display
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
display = Display(visible=0, size=(800,600))
display.start()
binary = FirefoxBinary('/usr/bin/firefox')
driver = webdriver.Firefox(firefox_binary=binary)
driver.get('https://www.baidu.com')
print(driver.title.encode('utf8'))
driver.quit()
display.stop()

pip安装所需包

#安装包
pip install requests
pip install Pillow
pip install httplib2
pip install excel

参考:

CentOS6.8 安装python2.7,pip以及yum

关注公众号西加加先生一起玩转Python

原文地址:https://www.cnblogs.com/ghostlee/p/12169058.html

时间: 2024-08-28 05:41:53

【docker】CentOS6.8+Python2.7+selenium+Firefox的搭建的相关文章

【docker】CentOS6.8+Python3.7+selenium+Firefox的搭建

当前Docker容器配置: Centos6.8 python2.6.6 openssl-1.0.1 目标Docker容器配置: Centos6.8 python3.7.4 openssl-1.1.1 selenium 3.141.0 geckodriver 0.15 firefox 52 Pillow 6.1.0 pytesseract 0.2.7 安装依赖环境 yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel s

ununtu16.04+python3+selenium+firefox环境搭建

一.初始配置: 1.安装完系统并配置好地址及DNS.2.设置root密码: sudo passwd root 3.更改云源: sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak sudo apt-get install vim sudo vim /etc/apt/sources.list # deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/

selenium,在Eclipse中打开fireFox浏览器报错:org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms

1. 相信很多同学刚接触selenium时,在Eclipse中打开fireFox浏览器是报报错:org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:...(异常代码太多此处省略) 在网上找了好多方法都是不能解决问题,结果是焦头烂额! 2.其实这是selenium的jar包和

脚本自动化装centos6.5 python2.6升级2.7

centos6.5 python2.6升级2.7 前提: 现有的yum源, 并且能通网 脚本会自动安装python2.7.8  . pip . easy .setuptools 正文: 代码内容 #!/bin/bash # a script to install python 2.7 on CentOS 6.x system. # CentOS 6.x has python 2.6 by default, while some software (e.g. django1.7) # need p

持续集成:采用Xvfb+Selenium+Firefox搭建linux服务器下的自动化测试环境

自动化测试属于软件测试的一部分,QTP.LoadRunner等都可以编写自动化测试脚本,但是QTP.LoadRunner等工具毕竟还需要人工操作,在持续集成思想下,软件应该自动发布并且自动测试,这样可以加快软件的开发测试周期,及时发现软件错误.持续集成应该包括代码的自动化检查.版本的自动化发布.以及程序的自动化测试.在自动化测试之外,再辅助以人工测试. 在我负责的项目中,代码自动化检查采用了SVN+CheckStyle实现,前文已有介绍,版本自动化发布采用了Jenkins或者crontab+An

Selenium2学习-038-firefox、webdriver版本不对称问题解决:org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055

今天有个朋友在群里问,为何脚本运行不通过,其脚本操作步骤简单描述如下: 1.启动火狐浏览器 2.打开百度 3.查询框输入关键字 4.点击按钮[百度一下] 脚本挺简单的,其给出的应用报错信息如下所示: [TestNG] Running: C:\Users\jiwei.xu\AppData\Local\Temp\testng-eclipse--429788523\testng-customsuite.xml org.openqa.selenium.firefox.NotConnectedExcept

Selenium firefox 路径设置问题

方法一:重新安装Firefox在默认路径下. 方法二:直接用System.setProperty方法设置webdriver.firefox.bin的值 import org.junit.After;import org.junit.Before;import org.junit.Test;import org.openqa.selenium.WebDriver;import org.openqa.selenium.firefox.FirefoxDriver; public class Firef

Selenium Firefox 官方Webdriver -- Geckodriver 下载地址

Selenium Firefox 官方Webdriver -- Geckodriver 下载地址 https://github.com/mozilla/geckodriver/releases

python+selenium自动化环境搭建之后,能打开firefox,却不能执行自动化操作

python+selenium自动化环境搭建之后,选择执行,能够打开firefox,但是却不能继续执行后续操作.原因是selenium的版本与firefox的版本不兼容. 解决办法: 1.将firefox降到与selenium相对应的版本.例如我使用selenium版本是3.3.3,那我对应的firefox版本是52.0.2,如果firefox继续升级,也会出现不兼容的情况.建议可以在firefox的工具--选项--高级中设置为不检查更新,以免软件自动更新出现问题. 2.安装该浏览器版本对应的g