Centos下实现使用tesseract破解验证码

      实现使用tesseract实现自动识别验证码,然后使用python搭建守护进程进行监听。

一、首先要安装Python

       centos下默认的最新版本是2.6.6,为了更好的兼容性,我这里安装python2.7.11.
    1),先安装GCC,用如下命令yum install gcc gcc-c++  openssl-devel
    2)下载Python-2.7.11.tar.xz文件,wget  https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tar.xz
     3)下载后放到/usr/local/src/下,进行解压
tar -Jxvf Python-2.7.11.tar.xz
cd Python-2.7.11
mkdir /usr/local/python2.7
./configure --prefix=/usr/local/python2.7
make all
make install

清除之前编译的可执行文件及配置文件。 
make clean 
清除所有生成的文件 
make distclean
由于系统默认给是2.6,所以先清除/usr/bin/python
rm -rf /usr/bin/python

建立软连接
ln -s /usr/local/python2.7/bin/python2.7 /usr/bin/python

可以用python -V查看,
安装python扩展包
ln -s /usr/local/python2.7/bin/python2.7 /usr/bin/python

然后执行
python ez_setup.py               发现此方法安装不上,出现问题,setup_tool安装不上,去官网查看,把ez_setup包下载下来。
wget https://pypi.python.org/packages/ba/2c/743df41bd6b3298706dfe91b0c7ecdc47f2dc1a3104abeb6e9aa4a45fa5d/ez_setup-0.9.tar.gz
tar zxvf ez_setup-0.9.tar.gz
cd ez_setup-0.9
python ez_setup.py


虽然现在python已经安装完成,但是使用yum命令会有问题——yum不能正常工作:

# yum list
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:
No module named yum
Please install a package which provides this module, or
verify that the module is installed correctly.
It's possible that the above module doesn't match the

current version of Python

这是因为yum默认使用的python版本是2.6.6,到哪是现在的python版本是2.7.5,故会出现上述问题,只需要该一下yum的默认python配置版本就行了:

#vi /usr/bin/yum

将文件头部的#!/usr/bin/python改为

#/usr/bin/python2.6

二、安装tesseract

yum install -y tesseract

既可安装,安装的版本是3.04
安装好后既可以使用其来使用进行图片的识别,
tesseract phototest.tif phototest -l eng

他会生成一个phototest的文件,里面就是所识别得内容

三、安装PIL

1)安装PIL所需的系统库文件,参考PIL的REDEME文件,需要如下依赖库
yum install zlib zlib-devel libjpeg libjpeg-devel freetype freetype-devel
2)删除Python下安装的PIL
cd /usr/local/python2.7/lib/python2.7/site-packages
3)下载PIL软件包
wget http://effbot.org/media/downloads/Imaging-1.1.7.tar.gz
tar -zxvf Imaging-1.1.7.tar.gz
cd Imaging-1.1.7
 python setup.py build_ext -i  #用来进行安装前的检查

 #修改setup.py,通过指令  vim setup.py   其中yum安装的依赖库需要用rpm -ql 包名查看安装位置。 
TCL_ROOT = "/usr/lib64/"
JPEG_ROOT = "/usr/lib64/"
ZLIB_ROOT = "/usr/lib64/"
TIFF_ROOT = "/usr/lib64/"
FREETYPE_ROOT = "/usr/lib64/"
LCMS_ROOT = "/usr/lib64/"

安装
$ python setup.py install

四、安装pytesser

pytesser项目目前为止只有0.0.1版本,并且代码托管在谷歌,无法获取,我是在百度网盘下载,
下载完成后,放到python安装模块下
/usr/local/python2.7/lib/python2.7/site-packages/下
在其目录下,可以进行测试
写一个test.py脚本
环境变量pythonpath 
在/etc/profile.d/
vim pythonpath.sh
输入:
export PYTHONPATH=/usr/local/python2.7/lib/python2.7/site-packages/:/usr/local/python2.7/lib/python2.7/site-packages/pytesser_v0.0.1
保存退出
source /etc/profile.d/pythonpath.sh
即可。




五、安装web.py

官网:webpy.org
下载web.py 
wget http://webpy.org/static/web.py-0.37.tar.gz
tar zxvf web.py-0.37.tar.gz
cd /web.py-0.37
python setup.py install

或者使用
/usr/local/python2.7/bin/easy_install web.py

把写好的Python脚本加入到系统启动当中,并系统重启自动启动,后台运行
在/etc/init.d/目录下新建一个启动脚本名字叫做chimgtoword
在其中加入如下内容:

#!/bin/bash
#add for chkconfig
#chkconfig: 2345 70 30
#description: the description of the shell 
#processname: chimgtoword
#author:
#date:
执行
nohup /usr/bin/python /usr/local/bin/changeImgToWords.py 2>>/dev/null &
保存退出。
增加可执行权限,
[root@iZ94boyb8fpZ ~]# chmod a+x /etc/init.d/chimgtoword
[root@iZ94boyb8fpZ ~]# chkconfig --add chimgtoword
[root@iZ94boyb8fpZ ~]# chkconfig --list|grep chimgtoword
chimgtoword        0:off    1:off    2:on    3:on    4:on    5:on    6:off
[root@iZ94boyb8fpZ ~]# chkconfig chimgtoword on
启动服务:
[root@iZ94boyb8fpZ ~]# /etc/init.d/chimgtoword
查看服务是否启动

查看端口是否打开:


猜你喜欢

转载自blog.csdn.net/qq625281334/article/details/53183564