dunphy 发表于 2014-9-22 14:25:43

带有一些杂线条的验证码问题【已解决】

本帖最后由 dunphy 于 2014-10-11 14:09 编辑

回复 2# lynfr8
最近在补录检查的数据,请前辈看看这个网站的代码验证码能不能识别,带有一些杂线条的网页验证码
http://182.139.135.21:85/FrameSet/Login.aspx   
验证码的图片地址:http://182.139.135.21:85/FrameSet/ValidateImage.aspx?s=0.05308202673832768

刚才试了试diandiand163前辈的识库别,将亮度小于68以上就能支掉那些线条
希望前辈能帮帮忙。

dunphy 发表于 2014-9-22 16:26:01

大大们都不在么》?在线急等

seniors 发表于 2014-9-23 20:58:40

本帖最后由 seniors 于 2014-9-23 21:06 编辑

这个是位置固定,颜色固定的,把我那个帖子消化一下,只取一种颜色就能把字提取出来了

把那个二色化的参数改一下就行了

dunphy 发表于 2014-9-23 23:35:28

本帖最后由 dunphy 于 2014-9-23 23:48 编辑

回复 3# seniors

正是用你这个工具弄出来了。我该怎么把验证码输入到网页中???
#include <IE.au3>
#include <MsgBoxConstants.au3>
Local $username ="111111"
Local$passwd = "111111"
$oIE = _IECreate ("http://182.139.135.21:85/FrameSet/Login.aspx")
$oForm = _IEFormGetObjByName ($oIE, "form1");找一个名字叫"form1"的form表单
$ouser = _IEFormElementGetObjByName ($oForm, "txtUserName");从上面的form1表单里找一个名字叫txtUserName的单元
$opasswd = _IEFormElementGetObjByName ($oForm, "txtPwd");从上面的form表单里找一个名字叫txtPwd的单元
_IEFormElementSetValue ($ouser, $username);设置值
_IEFormElementSetValue ($opasswd, $passwd);设置值
$oSubmit = _IEFormElementGetObjByName ($oForm, "ImageButton1");从上面的form表单里找一个名字叫ImageButton1的单元
_IEAction ($oSubmit, "click");做click的action
$Ele = _IEGetObjById($oIE,"txtValidateCode")
_IEFormElementSetValue($Ele,_yzhengma())
Send("{ENTER}")
;识别验证码程序
func _yzhengma()

EndFunc
顺便附上从你那个软件我的输出程序,(忘了告诉前辈此验证码里面没有9),基本上都能识别(怕识别不出来的时候显示符号"-"特加个判断让它重新刷新重新识别 )
#include <INet.au3>
#include <GDIPlus.au3>
#include <Array.au3>
#include <Memory.au3>
;0-9的数字值
$yzm = "http://182.139.135.21:85/FrameSet/ValidateImage.aspx"
$left = 3
$top = 4
$zhong = 1
$ziWidth = 7
$ziHeight = 11
$zishu = 4
Global $n[$ziHeight] = [["0011100","0100010","0100010","0100001","1100001","1000001","1100001","0100001","0100010","0100010","0011100"], _
["0001000","0011000","0001000","0001000","0001000","0001000","0001000","0001000","0001000","0001000","0011110"], _
["0011100","0100110","0000010","0000010","0000010","0000000","0000100","0001000","0010000","0100001","1111110"], _
["0011100","0100110","0000010","0000000","0000000","0011110","0000110","0000010","0000010","0000000","1111000"], _
["0000100","0000100","0001100","0010100","0000100","0100100","0000100","1111111","0000100","0000100","0000100"], _
["0001110","0010000","0000000","0111000","0001100","0000010","0000010","0000010","0000010","0000000","0111000"], _
["0000111","0001100","0010000","0110000","0101110","1100011","1100011","1000001","0100001","0110010","0011100"], _
["0111111","0000000","0000010","0000010","0000000","0000100","0000100","0000000","0001000","0001000","0000000"], _
["0011100","0100010","0100010","0100010","0010000","0011100","0010110","0100010","0100001","0100010","0011100"], _
["","","","","","","","","","",""]]
$hGui = GUICreate("识别例子", 200, 60)

$Pic1 = GUICtrlCreatePic("", 14, 10, 50, 20)
Global $hPic = GUICtrlGetHandle(-1)
$Label1 = GUICtrlCreateLabel("点击我的上方", 14, 40, 80, 17)

GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
            Case -3
                  GUIDelete()
                  Exit
                Case $Pic1
                        if StringInStr ("myYzmShibie($yzm)","-") then
                              MsgBox(0,"提示","识别不了,请重新选择")
                        else
                        GUICtrlSetData($Label1, myYzmShibie($yzm))
                        EndIf
    EndSwitch
WEnd

Func myYzmShibie($URL, $func_bg = 0x808080)
    Local $BitmapData, $i_width, $i_height, $Scan0, $pixelData, $s_BMPData, $i_Stride
    _GDIPlus_Startup()
    ;获取图片
    $bImage = _INetGetSource($URL, False)
    $bData = Binary($bImage)
    $Lenght = BinaryLen($bData)
    $hData = _MemGlobalAlloc($Lenght, 0x0002)
    $pData = _MemGlobalLock($hData)
    $tData = DllStructCreate("byte[" & $Lenght & "]", $pData)
    DllStructSetData($tData, 1, $bData)
    _MemGlobalUnlock($hData)
    $pStream = _WinAPI_CreateStreamOnHGlobal($hData)
    $hImage = _GDIPlus_BitmapCreateFromStream($pStream)
    ;转换图片到pic控件显示
    $hBitMap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    ;把图片读入数组,来自阿福源码
    $i_width = _GDIPlus_ImageGetWidth($hImage)
    $i_height = _GDIPlus_ImageGetHeight($hImage)
    $BitmapData = _GDIPlus_BitmapLockBits($hImage, 0, 0, $i_width, $i_height, $GDIP_ILMREAD, $GDIP_PXF24RGB)
    $i_Stride = DllStructGetData($BitmapData, "Stride");Stride - Offset, in bytes, between consecutive scan lines of the bitmap. If the stride is positive, the bitmap is top-down. If the stride is negative, the bitmap is bottom-up.
    $Scan0 = DllStructGetData($BitmapData, "Scan0");Scan0 - Pointer to the first (index 0) scan line of the bitmap.
    $pixelData = DllStructCreate("ubyte lData[" & (Abs($i_Stride) * $i_height) & "]", $Scan0)
    ;不要使用官方论坛上提供的Abs($i_Stride) * $i_height-1,否则无法正确处理gif冗余等情形
    $s_BMPData = DllStructGetData($pixelData, "lData")
    $s_BMPData = StringTrimLeft($s_BMPData, 2);去掉头部"0x"
    _GDIPlus_ImageDispose($hImage)
    _MemGlobalFree($hData)
    _GDIPlus_Shutdown()
    ;设置到pic控件
    $oldObj = _SendMessage($hPic, 0x0172, 0, $hBitMap)
    _WinAPI_DeleteObject($oldObj)
    Local $hObj = _SendMessage($hPic, 0x0173)
    If $hObj <> $hBitMap Then
            _WinAPI_DeleteObject($hBitMap)
    EndIf
    DllCall("psapi.dll", "int", "EmptyWorkingSet", "hWnd", -1)
    ;处理图片数组
    Local $a_return[$i_width][$i_height], $x, $y, $s
    Local $ls = "", $lls = ""
    For $y = $top To $top + $ziHeight -1;5和4分别是图片上下的空边
            $s = StringMid($s_BMPData, $y * ($i_Stride * 2) + 1, $i_width * 6)
            For $x = $left To $left + $zishu * $ziWidth + ($zishu - 1) * $zhong - 1;6和9分别是图片左右的空边
                  $a_return[$x][$y] = Number("0x" & StringMid($s, $x * 6 + 1, 6))
                  $a_return[$x][$y] = Graycolor($a_return[$x][$y], "blue")
                  If $a_return[$x][$y] < $func_bg Then
                            $a_return[$x][$y] = 1
                  Else
                            $a_return[$x][$y] = 0
                  EndIf
            Next
        Next

    Local $Number = ""
    For $i = 0 To $zishu - 1;读取4个数字的值
            $sx = $left + $ziWidth * $i + $zhong * $i;6是第一个数字的起点,每个数字占9列,第9列是空白列
            For $y = $top To $top + $ziHeight -1;5和4分别是图片上下的空边
                  $ls = ""
                  For $x = $sx To $sx + $ziWidth - 1;因为每个数字占9列,第9列是空白列,所以只读取8列

                            If $a_return[$x][$y] = 1 Then
                                    $ls &= "1"
                            Else
                                    $ls &= "0"
                            EndIf
                  Next
                  $ls &= "|"
                  $lls = $lls & $ls
            Next
            $Number &= WhatNumber($lls)
            $lls = ""
    Next
    Return $Number

EndFunc   ;==>myYzmShibie

Func WhatNumber($Sum)
    Local $checktotal, $aCheck = StringSplit($Sum, "|")
    For $i = 0 To 9 ;9是数字只有9个
            $checktotal = 0
            For $j = 0 To $ziHeight - 1
                  If $n[$i][$j] <> $aCheck[$j + 1] Then $checktotal += 1
                  If $checktotal > 1 Then ExitLoop
            Next
            If $checktotal < 2 Then Return $i
    Next
    Return -1
EndFunc   ;==>WhatNumber

Func Graycolor($color, $style = "all")
    Local $a_return, $b, $g, $r, $ret
    Switch $style
            Case "blue"
                  $b = BitAND(0xFF, BitShift($color, 16))
                  $a_return = BitOR(BitShift($b, -16), BitShift($b, -8), $b)
            Case "green"
                  $g = BitAND(0xFF, BitShift($color, 8))
                  $a_return = BitOR(BitShift($g, -16), BitShift($g, -8), $g)
            Case "red"
                  $r = BitAND(0xFF, $color)
                  $a_return = BitOR(BitShift($r, -16), BitShift($r, -8), $r)
            Case "all"
                  $b = BitAND(0xFF, BitShift($color, 16))
                  $g = BitAND(0xFF, BitShift($color, 8))
                  $r = BitAND(0xFF, $color)
                  $ret = Int((30 * $r + $g * 59 + $b * 11) / 100)
                  $b = BitAND(0xFF0000, BitShift($ret, -16))
                  $g = BitAND(0x00FF00, BitShift($ret, -8))
                  $r = $ret
                  $a_return = BitOR($b, $g, $r)
    EndSwitch
    Return $a_return
EndFunc   ;==>Graycolor

seniors 发表于 2014-9-24 07:24:44

Func myYzmShibie($URL, $func_bg = 0x808080)
就是你的程序里要的识别用的
不过可能你用的内嵌IE方法,可能识别出来的,不是你现在内嵌在IE中的验证码

dunphy 发表于 2014-9-24 16:10:16

回复 5# seniors

前辈,正如你所说,识别出来的跟上面显示不同步。咱办?#include <IE.au3>
#include <MsgBoxConstants.au3>
#include <INet.au3>
#include <GDIPlus.au3>
#include <Array.au3>
#include <Memory.au3>



Local $username ="111111"
Local$passwd = "111111"
$oIE = _IECreate ("http://182.139.135.21:85/FrameSet/Login.aspx")
$oForm = _IEFormGetObjByName ($oIE, "form1");找一个名字叫"form1"的form表单
$ouser = _IEFormElementGetObjByName ($oForm, "txtUserName");从上面的form1表单里找一个名字叫txtUserName的单元
$opasswd = _IEFormElementGetObjByName ($oForm, "txtPwd");从上面的form表单里找一个名字叫txtPwd的单元
_IEFormElementSetValue ($ouser, $username);设置值
_IEFormElementSetValue ($opasswd, $passwd);设置值
$oSubmit = _IEFormElementGetObjByName ($oForm, "ImageButton1");从上面的form表单里找一个名字叫ImageButton1的单元
_IEAction ($oSubmit, "click");做click的action



$left = 3
$top = 4
$zhong = 1
$ziWidth = 7
$ziHeight = 11
$zishu = 4
Global $n[$ziHeight] = [["0011100","0100010","0100010","0100001","1100001","1000001","1100001","0100001","0100010","0100010","0011100"], _
["0001000","0011000","0001000","0001000","0001000","0001000","0001000","0001000","0001000","0001000","0011110"], _
["0011100","0100110","0000010","0000010","0000010","0000000","0000100","0001000","0010000","0100001","1111110"], _
["0011100","0100110","0000010","0000000","0000000","0011110","0000110","0000010","0000010","0000000","1111000"], _
["0000100","0000100","0001100","0010100","0000100","0100100","0000100","1111111","0000100","0000100","0000100"], _
["0001110","0010000","0000000","0111000","0001100","0000010","0000010","0000010","0000010","0000000","0111000"], _
["0000111","0001100","0010000","0110000","0101110","1100011","1100011","1000001","0100001","0110010","0011100"], _
["0111111","0000000","0000010","0000010","0000000","0000100","0000100","0000000","0001000","0001000","0000000"], _
["0011100","0100010","0100010","0100010","0010000","0011100","0010110","0100010","0100001","0100010","0011100"], _
["","","","","","","","","","",""]]

Global $hPic = GUICtrlGetHandle(-1)


$Ele = _IEGetObjById($oIE,"txtValidateCode")
_IEFormElementSetValue($Ele,myYzmShibie("http://182.139.135.21:85/FrameSet/ValidateImage.aspx"))


;Send("{ENTER}")
;识别验证码程序

Func myYzmShibie($URL, $func_bg = 0x808080)
    Local $BitmapData, $i_width, $i_height, $Scan0, $pixelData, $s_BMPData, $i_Stride
    _GDIPlus_Startup()
    ;获取图片
    $bImage = _INetGetSource($URL, False)
    $bData = Binary($bImage)
    $Lenght = BinaryLen($bData)
    $hData = _MemGlobalAlloc($Lenght, 0x0002)
    $pData = _MemGlobalLock($hData)
    $tData = DllStructCreate("byte[" & $Lenght & "]", $pData)
    DllStructSetData($tData, 1, $bData)
    _MemGlobalUnlock($hData)
    $pStream = _WinAPI_CreateStreamOnHGlobal($hData)
    $hImage = _GDIPlus_BitmapCreateFromStream($pStream)
    ;转换图片到pic控件显示
    $hBitMap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    ;把图片读入数组,来自阿福源码
    $i_width = _GDIPlus_ImageGetWidth($hImage)
    $i_height = _GDIPlus_ImageGetHeight($hImage)
    $BitmapData = _GDIPlus_BitmapLockBits($hImage, 0, 0, $i_width, $i_height, $GDIP_ILMREAD, $GDIP_PXF24RGB)
    $i_Stride = DllStructGetData($BitmapData, "Stride");Stride - Offset, in bytes, between consecutive scan lines of the bitmap. If the stride is positive, the bitmap is top-down. If the stride is negative, the bitmap is bottom-up.
    $Scan0 = DllStructGetData($BitmapData, "Scan0");Scan0 - Pointer to the first (index 0) scan line of the bitmap.
    $pixelData = DllStructCreate("ubyte lData[" & (Abs($i_Stride) * $i_height) & "]", $Scan0)
    ;不要使用官方论坛上提供的Abs($i_Stride) * $i_height-1,否则无法正确处理gif冗余等情形
    $s_BMPData = DllStructGetData($pixelData, "lData")
    $s_BMPData = StringTrimLeft($s_BMPData, 2);去掉头部"0x"
    _GDIPlus_ImageDispose($hImage)
    _MemGlobalFree($hData)
    _GDIPlus_Shutdown()
    ;设置到pic控件
    $oldObj = _SendMessage($hPic, 0x0172, 0, $hBitMap)
    _WinAPI_DeleteObject($oldObj)
    Local $hObj = _SendMessage($hPic, 0x0173)
    If $hObj <> $hBitMap Then
            _WinAPI_DeleteObject($hBitMap)
    EndIf
    DllCall("psapi.dll", "int", "EmptyWorkingSet", "hWnd", -1)
    ;处理图片数组
    Local $a_return[$i_width][$i_height], $x, $y, $s
    Local $ls = "", $lls = ""
    For $y = $top To $top + $ziHeight -1;5和4分别是图片上下的空边
            $s = StringMid($s_BMPData, $y * ($i_Stride * 2) + 1, $i_width * 6)
            For $x = $left To $left + $zishu * $ziWidth + ($zishu - 1) * $zhong - 1;6和9分别是图片左右的空边
                  $a_return[$x][$y] = Number("0x" & StringMid($s, $x * 6 + 1, 6))
                  $a_return[$x][$y] = Graycolor($a_return[$x][$y], "blue")
                  If $a_return[$x][$y] < $func_bg Then
                            $a_return[$x][$y] = 1
                  Else
                            $a_return[$x][$y] = 0
                  EndIf
            Next
      Next

    Local $Number = ""
    For $i = 0 To $zishu - 1;读取4个数字的值
            $sx = $left + $ziWidth * $i + $zhong * $i;6是第一个数字的起点,每个数字占9列,第9列是空白列
            For $y = $top To $top + $ziHeight -1;5和4分别是图片上下的空边
                  $ls = ""
                  For $x = $sx To $sx + $ziWidth - 1;因为每个数字占9列,第9列是空白列,所以只读取8列

                            If $a_return[$x][$y] = 1 Then
                                    $ls &= "1"
                            Else
                                    $ls &= "0"
                            EndIf
                  Next
                  $ls &= "|"
                  $lls = $lls & $ls
            Next
            $Number &= WhatNumber($lls)
            $lls = ""
    Next
    Return $Number

EndFunc   ;==>myYzmShibie

Func WhatNumber($Sum)
    Local $checktotal, $aCheck = StringSplit($Sum, "|")
    For $i = 0 To 9 ;9是数字只有9个
            $checktotal = 0
            For $j = 0 To $ziHeight - 1
                  If $n[$i][$j] <> $aCheck[$j + 1] Then $checktotal += 1
                  If $checktotal > 1 Then ExitLoop
            Next
            If $checktotal < 2 Then Return $i
    Next
    Return -1
EndFunc   ;==>WhatNumber

Func Graycolor($color, $style = "all")
    Local $a_return, $b, $g, $r, $ret
    Switch $style
            Case "blue"
                  $b = BitAND(0xFF, BitShift($color, 16))
                  $a_return = BitOR(BitShift($b, -16), BitShift($b, -8), $b)
            Case "green"
                  $g = BitAND(0xFF, BitShift($color, 8))
                  $a_return = BitOR(BitShift($g, -16), BitShift($g, -8), $g)
            Case "red"
                  $r = BitAND(0xFF, $color)
                  $a_return = BitOR(BitShift($r, -16), BitShift($r, -8), $r)
            Case "all"
                  $b = BitAND(0xFF, BitShift($color, 16))
                  $g = BitAND(0xFF, BitShift($color, 8))
                  $r = BitAND(0xFF, $color)
                  $ret = Int((30 * $r + $g * 59 + $b * 11) / 100)
                  $b = BitAND(0xFF0000, BitShift($ret, -16))
                  $g = BitAND(0x00FF00, BitShift($ret, -8))
                  $r = $ret
                  $a_return = BitOR($b, $g, $r)
    EndSwitch
    Return $a_return
EndFunc   ;==>Graycolor

seniors 发表于 2014-9-24 17:42:56

用POST方式吧,

seniors 发表于 2014-9-24 19:48:22

内嵌IE我看只能用剪切板了,如下

#include <IE.au3>
#include <MsgBoxConstants.au3>
#include <INet.au3>
#include <GDIPlus.au3>
#include <Array.au3>
#include <Memory.au3>
#include <Clipboard.au3>


Local $username = "111111"
Local $passwd = "111111"
$oIE = _IECreate("http://182.139.135.21:85/FrameSet/Login.aspx")
$oForm = _IEFormGetObjByName($oIE, "form1");找一个名字叫"form1"的form表单
$ouser = _IEFormElementGetObjByName($oForm, "txtUserName");从上面的form1表单里找一个名字叫txtUserName的单元
$opasswd = _IEFormElementGetObjByName($oForm, "txtPwd");从上面的form表单里找一个名字叫txtPwd的单元
_IEFormElementSetValue($ouser, $username);设置值
_IEFormElementSetValue($opasswd, $passwd);设置值
$oSubmit = _IEFormElementGetObjByName($oForm, "ImageButton1");从上面的form表单里找一个名字叫ImageButton1的单元
_IEAction($oSubmit, "click");做click的action


$left = 3
$top = 4
$zhong = 1
$ziWidth = 7
$ziHeight = 11
$zishu = 4
Global $n[$ziHeight] = [["0011100", "0100010", "0100010", "0100001", "1100001", "1000001", "1100001", "0100001", "0100010", "0100010", "0011100"], _
                ["0001000", "0011000", "0001000", "0001000", "0001000", "0001000", "0001000", "0001000", "0001000", "0001000", "0011110"], _
                ["0011100", "0100110", "0000010", "0000010", "0000010", "0000000", "0000100", "0001000", "0010000", "0100001", "1111110"], _
                ["0011100", "0100110", "0000010", "0000000", "0000000", "0011110", "0000110", "0000010", "0000010", "0000000", "1111000"], _
                ["0000100", "0000100", "0001100", "0010100", "0000100", "0100100", "0000100", "1111111", "0000100", "0000100", "0000100"], _
                ["0001110", "0010000", "0000000", "0111000", "0001100", "0000010", "0000010", "0000010", "0000010", "0000000", "0111000"], _
                ["0000111", "0001100", "0010000", "0110000", "0101110", "1100011", "1100011", "1000001", "0100001", "0110010", "0011100"], _
                ["0111111", "0000000", "0000010", "0000010", "0000000", "0000100", "0000100", "0000000", "0001000", "0001000", "0000000"], _
                ["0011100", "0100010", "0100010", "0100010", "0010000", "0011100", "0010110", "0100010", "0100001", "0100010", "0011100"], _
                ["", "", "", "", "", "", "", "", "", "", ""]]


$Ele = _IEGetObjById($oIE, "txtValidateCode")
_IEFormElementSetValue($Ele, myYzmShibie("vcodeImg"))


;Send("{ENTER}")
;识别验证码程序

Func myYzmShibie($ImgId, $func_bg = 0x808080)
        Local $BitmapData, $i_width, $i_height, $Scan0, $pixelData, $s_BMPData, $i_Stride
        _GDIPlus_Startup()
        ;获取图片
        $oImg = $oIE.Document.getElementById($ImgId)
        $oPic = $oIE.Document.body.createControlRange()
        $oPic.Add($oImg)
        $oPic.execCommand("Copy")
        _ClipBoard_Open(0)
        $ivpics = _ClipBoard_GetDataEx($CF_BITMAP)
        _ClipBoard_Close()
        $hImage = _GDIPlus_BitmapCreateFromHBITMAP($ivpics)
        ;把图片读入数组,来自阿福源码
        $i_width = _GDIPlus_ImageGetWidth($hImage)
        $i_height = _GDIPlus_ImageGetHeight($hImage)
        $BitmapData = _GDIPlus_BitmapLockBits($hImage, 0, 0, $i_width, $i_height, $GDIP_ILMREAD, $GDIP_PXF24RGB)
        $i_Stride = DllStructGetData($BitmapData, "Stride");Stride - Offset, in bytes, between consecutive scan lines of the bitmap. If the stride is positive, the bitmap is top-down. If the stride is negative, the bitmap is bottom-up.
        $Scan0 = DllStructGetData($BitmapData, "Scan0");Scan0 - Pointer to the first (index 0) scan line of the bitmap.
        $pixelData = DllStructCreate("ubyte lData[" & (Abs($i_Stride) * $i_height) & "]", $Scan0)
        ;不要使用官方论坛上提供的Abs($i_Stride) * $i_height-1,否则无法正确处理gif冗余等情形
        $s_BMPData = DllStructGetData($pixelData, "lData")
        $s_BMPData = StringTrimLeft($s_BMPData, 2);去掉头部"0x"
        _GDIPlus_ImageDispose($hImage)
        _GDIPlus_Shutdown()
        DllCall("psapi.dll", "int", "EmptyWorkingSet", "hWnd", -1)
        ;处理图片数组
        Local $a_return[$i_width][$i_height], $x, $y, $s
        Local $ls = "", $lls = ""
        For $y = $top To $top + $ziHeight - 1;5和4分别是图片上下的空边
                $s = StringMid($s_BMPData, $y * ($i_Stride * 2) + 1, $i_width * 6)
                For $x = $left To $left + $zishu * $ziWidth + ($zishu - 1) * $zhong - 1;6和9分别是图片左右的空边
                        $a_return[$x][$y] = Number("0x" & StringMid($s, $x * 6 + 1, 6))
                        $a_return[$x][$y] = Graycolor($a_return[$x][$y], "blue")
                        If $a_return[$x][$y] < $func_bg Then
                                $a_return[$x][$y] = 1
                        Else
                                $a_return[$x][$y] = 0
                        EndIf
                Next
        Next

        Local $Number = ""
        For $i = 0 To $zishu - 1;读取4个数字的值
                $sx = $left + $ziWidth * $i + $zhong * $i;6是第一个数字的起点,每个数字占9列,第9列是空白列
                For $y = $top To $top + $ziHeight - 1;5和4分别是图片上下的空边
                        $ls = ""
                        For $x = $sx To $sx + $ziWidth - 1;因为每个数字占9列,第9列是空白列,所以只读取8列

                                If $a_return[$x][$y] = 1 Then
                                        $ls &= "1"
                                Else
                                        $ls &= "0"
                                EndIf
                        Next
                        $ls &= "|"
                        $lls = $lls & $ls
                Next
                $Number &= WhatNumber($lls)
                $lls = ""
        Next
        Return $Number

EndFunc   ;==>myYzmShibie

Func WhatNumber($Sum)
        Local $checktotal, $aCheck = StringSplit($Sum, "|")
        For $i = 0 To 9 ;9是数字只有9个
                $checktotal = 0
                For $j = 0 To $ziHeight - 1
                        If $n[$i][$j] <> $aCheck[$j + 1] Then $checktotal += 1
                        If $checktotal > 1 Then ExitLoop
                Next
                If $checktotal < 2 Then Return $i
        Next
        Return -1
EndFunc   ;==>WhatNumber

Func Graycolor($color, $style = "all")
        Local $a_return, $b, $g, $r, $ret
        Switch $style
                Case "blue"
                        $b = BitAND(0xFF, BitShift($color, 16))
                        $a_return = BitOR(BitShift($b, -16), BitShift($b, -8), $b)
                Case "green"
                        $g = BitAND(0xFF, BitShift($color, 8))
                        $a_return = BitOR(BitShift($g, -16), BitShift($g, -8), $g)
                Case "red"
                        $r = BitAND(0xFF, $color)
                        $a_return = BitOR(BitShift($r, -16), BitShift($r, -8), $r)
                Case "all"
                        $b = BitAND(0xFF, BitShift($color, 16))
                        $g = BitAND(0xFF, BitShift($color, 8))
                        $r = BitAND(0xFF, $color)
                        $ret = Int((30 * $r + $g * 59 + $b * 11) / 100)
                        $b = BitAND(0xFF0000, BitShift($ret, -16))
                        $g = BitAND(0x00FF00, BitShift($ret, -8))
                        $r = $ret
                        $a_return = BitOR($b, $g, $r)
        EndSwitch
        Return $a_return
EndFunc   ;==>Graycolor

dunphy 发表于 2014-9-24 23:39:43

本帖最后由 dunphy 于 2014-9-25 01:49 编辑

回复 8# seniors

谢谢前辈,在360浏览器上已经通过测试。还有二个问题
第一,万一识别出来的验证码失败.如:11-18       能不能加个判断,点击验证图片(看不清楚换一张)再重新输入新的验证码到INPUT框中
其二,如下图:
在IE8.0的浏览器默认安全级别下要弹 允许网页访问剪贴版的窗口,这个能不能也加个判断,是不是IE,如果是IE浏览器 点击允许 或者在这里先启用IE允许对剪贴版进行编程使用

seniors 发表于 2014-9-25 07:12:22

这个判断就自己想办法吧,动动手动动脑,很好的

dunphy 发表于 2014-9-25 15:33:53

本帖最后由 dunphy 于 2014-10-11 14:05 编辑

回复 10# seniors
在WIN7专业版下,程序运行时,不开360浏览器,还打不开。晕倒。先打开浏览器,再运行这个程序的时候,有时候就卡在登陆界面上,有时候卡在主页上不动。有时候卡在新增那里,不知道怎么回事,前辈帮帮忙
等着完成9个月的记录,着急。。。。。先在此谢谢了
#include <IE.au3>
#include <MsgBoxConstants.au3>
#include <INet.au3>
#include <GDIPlus.au3>
#include <Array.au3>
#include <Memory.au3>
#include <Clipboard.au3>
#include <String.au3>
HotKeySet("{ESC}", "Terminate") ;设置个热键按ESC退出程序

Local $username = "XXXXX"
Local $passwd = "XXXXX"
$oIE = _IECreate("http://182.139.135.21:85/FrameSet/Login.aspx")
$oForm = _IEFormGetObjByName($oIE, "form1");找一个名字叫"form1"的form表单
$ouser = _IEFormElementGetObjByName($oForm, "txtUserName");从上面的form1表单里找一个名字叫txtUserName的单元
$opasswd = _IEFormElementGetObjByName($oForm, "txtPwd");从上面的form表单里找一个名字叫txtPwd的单元
_IEFormElementSetValue($ouser, $username);设置帐号
_IEFormElementSetValue($opasswd, $passwd);设置密码
$oSubmit = _IEFormElementGetObjByName($oForm, "ImageButton1");从上面的form表单里找一个名字叫ImageButton1的单元
_IEAction($oSubmit, "click");模拟点击指定的ImageButton1元素.叫做click的action

$left = 3
$top = 4
$zhong = 1
$ziWidth = 7
$ziHeight = 11
$zishu = 4
Global $n[$ziHeight] = [["0011100", "0100010", "0100010", "0100001", "1100001", "1000001", "1100001", "0100001", "0100010", "0100010", "0011100"], _
                ["0001000", "0011000", "0001000", "0001000", "0001000", "0001000", "0001000", "0001000", "0001000", "0001000", "0011110"], _
                ["0011100", "0100110", "0000010", "0000010", "0000010", "0000000", "0000100", "0001000", "0010000", "0100001", "1111110"], _
                ["0011100", "0100110", "0000010", "0000000", "0000000", "0011110", "0000110", "0000010", "0000010", "0000000", "1111000"], _
                ["0000100", "0000100", "0001100", "0010100", "0000100", "0100100", "0000100", "1111111", "0000100", "0000100", "0000100"], _
                ["0001110", "0010000", "0000000", "0111000", "0001100", "0000010", "0000010", "0000010", "0000010", "0000000", "0111000"], _
                ["0000111", "0001100", "0010000", "0110000", "0101110", "1100011", "1100011", "1000001", "0100001", "0110010", "0011100"], _
                ["0111111", "0000000", "0000010", "0000010", "0000000", "0000100", "0000100", "0000000", "0001000", "0001000", "0000000"], _
                ["0011100", "0100010", "0100010", "0100010", "0010000", "0011100", "0010110", "0100010", "0100001", "0100010", "0011100"], _
                ["", "", "", "", "", "", "", "", "", "", ""]]


$Ele = _IEGetObjById($oIE, "txtValidateCode")

;这里该加上判断,如果验证码失败,重新点击图片获取
;如果是浏览器IE8,启用IE允许对剪贴版进行编程使用

_IEFormElementSetValue($Ele, myYzmShibie("vcodeImg"))   ;设置验证码
                                          
;ControlClick("Internet Explorer","","Button")
Send("{ENTER}")                                          ;发送回车健 相当于点击登陆按钮                        
Sleep(1000)                                              ;休息一秒钟,等待进入录入网页

;开始刷机





$oIEdk = _IEAttach("http://182.139.135.21:85/FrameSet/frame_HJH.aspx", "url");返回所有指向 IE 对象的对象变量
$oIEjr = _IEFrameGetObjByName($oIEdk, "topFrame")                              ;返回框架内对象变量指向的窗口对象
_IELinkClickByText($oIEjr, " 消防工作记录")                                    ;点击菜单栏的消防工作记录选项
Sleep(300)   ;等待页面刷新
_IELinkClickByText($oIEjr, "每日防火巡查 ")                                       ;点击菜单栏的每日防火巡查选项
Sleep(300)    ;等待页面刷新

;循环作业开始

Local $XCCS = 4                   ;设置巡查次数
Local $XCY = "张三,李四"         ;设置巡查人
Local $JCR = "李四"               ;设置检查人
Local $FXWT = "建筑消防设施设备完整好用"          ;设置检查内容

Local $j                              ;定义循环变量
For $j = 257 To 1                     
        Local $LrDate = _DateAdd('d', -$j, _NowCalcDate()) ;计算当前日期-258天得到所要开始的2014/01/11起始的日期 YYYY/MM/DD
        Local $ArrayLrDate = _StringExplode($LrDate, "/", 0) ;拆分日期字符串,返回包含字符串拆分后的数组.
        Local $RQ = $ArrayLrDate & "年" & $ArrayLrDate & "月" & $ArrayLrDate & "日" ;重新组合为YYYY年MM月DD日即Y2014年01月11日

        ;检查日期同上
        Local $JcDate = _DateAdd('d', -$j + 1, _NowCalcDate())
        Local $aArrayJcDate = _StringExplode($JcDate, "/", 0)
        ;MsgBox(0, "",$aArrayJcDate&$aArrayJcDate)

        If $aArrayJcDate & $aArrayJcDate = 0201 Then
                $aArrayJcDate = "01"
                $aArrayJcDate = 31
        EndIf
        If $aArrayJcDate & $aArrayJcDate = 0301 Then
                $aArrayJcDate = "02"
                $aArrayJcDate = 28
        EndIf
        If $aArrayJcDate & $aArrayJcDate = 0401 Then
                $aArrayJcDate = "03"
                $aArrayJcDate = 31
        EndIf
        If $aArrayJcDate & $aArrayJcDate = 0501 Then
                $aArrayJcDate = "04"
                $aArrayJcDate = 30
        EndIf
        If $aArrayJcDate & $aArrayJcDate = 0601 Then
                $aArrayJcDate = "05"
                $aArrayJcDate = 31
        EndIf
        If $aArrayJcDate & $aArrayJcDate = 0701 Then
                $aArrayJcDate = "06"
                $aArrayJcDate = 30
        EndIf
        If $aArrayJcDate & $aArrayJcDate = 0801 Then
                $aArrayJcDate = "07"
                $aArrayJcDate = 31
        EndIf
        If $aArrayJcDate & $aArrayJcDate = 0901 Then
                $aArrayJcDate = "08"
                $aArrayJcDate = 31
        EndIf
        If $aArrayJcDate & $aArrayJcDate = 1001 Then
                $aArrayJcDate = "09"
                $aArrayJcDate = 30
        EndIf
        $JCRQ = $aArrayJcDate & "年" & $aArrayJcDate & "月" & $aArrayJcDate & "日"
        Local $bh = 14268 - $j ;设置编号起始数

        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;调试开始
        ;MsgBox (0,"",$RQ)
        ;MsgBox (0,"",$JCRQ)
        ;MsgBox (0,"",$bh)
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;调试结束

        $oIElr = _IEFrameGetObjByName($oIEdk, "MainFrame")
        $Elexz = _IEGetObjById($oIElr, "ctl00_MainContent_Button1")    ;返回IE框架对象指向的新增按钮对象
        Sleep(3000)                                                            
        _IEAction($Elexz, "click") ;点击新增
       
       
        WinWaitActive("", "", 3)
;        Local $cs=WinWaitActive("", "", 3) ;等待每日防火巡查记录表出现
        ;If $cs=0 Then
        ;        _IEAction($Elexz, "click") ;点击新增
        ;EndIf
        ;设置日期
        $EleRQ = _IEGetObjById($oIElr, "ctl00_MainContent_txtRQ")
        _IEFormElementSetValue($EleRQ, $RQ)
        ;设置编号
        $EleBH = _IEGetObjById($oIElr, "ctl00_MainContent_txtBH")
        _IEFormElementSetValue($EleBH, $bh)
        ;设置巡查人
        $EleXCY = _IEGetObjById($oIElr, "ctl00_MainContent_txtXCY")
        _IEFormElementSetValue($EleXCY, $XCY)
        ;设置巡查次数
        $EleXCCS = _IEGetObjById($oIElr, "ctl00_MainContent_txtXCCS")
        _IEFormElementSetValue($EleXCCS, $XCCS)
        ;设置巡查发现的问题
        $EleFXWT = _IEGetObjById($oIElr, "ctl00_MainContent_txtFXWT")
        _IEPropertySet($EleFXWT, "innertext", $FXWT)
        ;设置检查人
        $EleJCR = _IEGetObjById($oIElr, "ctl00_MainContent_txtJCR")
        _IEFormElementSetValue($EleJCR, $JCR)
        ;设置检查时间
        $EleJCRQ = _IEGetObjById($oIElr, "ctl00_MainContent_txtJCRQ")
        _IEFormElementSetValue($EleJCRQ, $JCRQ)
        ;点击保存按钮
        $Eleadd = _IEGetObjById($oIElr, "ctl00_MainContent_btnAdd")
        _IEAction($Eleadd, "click")

        Send("{ENTER}") ;点击确认
    Sleep(1000)

Next

; 作业完成





;识别验证码程序

Func myYzmShibie($ImgId, $func_bg = 0x808080)
        Local $BitmapData, $i_width, $i_height, $Scan0, $pixelData, $s_BMPData, $i_Stride
        _GDIPlus_Startup() ;初始化 Microsoft Windows GDI+.
        ;获取图片
        $oImg = $oIE.Document.getElementById($ImgId)
        $oPic = $oIE.Document.body.createControlRange()
        $oPic.Add($oImg)
        $oPic.execCommand("Copy")
        _ClipBoard_Open(0)
        $ivpics = _ClipBoard_GetDataEx($CF_BITMAP)
        _ClipBoard_Close()
        $hImage = _GDIPlus_BitmapCreateFromHBITMAP($ivpics)
        ;把图片读入数组,来自阿福源码
        $i_width = _GDIPlus_ImageGetWidth($hImage)
        $i_height = _GDIPlus_ImageGetHeight($hImage)
        $BitmapData = _GDIPlus_BitmapLockBits($hImage, 0, 0, $i_width, $i_height, $GDIP_ILMREAD, $GDIP_PXF24RGB)
        $i_Stride = DllStructGetData($BitmapData, "Stride");Stride - Offset, in bytes, between consecutive scan lines of the bitmap. If the stride is positive, the bitmap is top-down. If the stride is negative, the bitmap is bottom-up.
        $Scan0 = DllStructGetData($BitmapData, "Scan0");Scan0 - Pointer to the first (index 0) scan line of the bitmap.
        $pixelData = DllStructCreate("ubyte lData[" & (Abs($i_Stride) * $i_height) & "]", $Scan0)
        ;不要使用官方论坛上提供的Abs($i_Stride) * $i_height-1,否则无法正确处理gif冗余等情形
        $s_BMPData = DllStructGetData($pixelData, "lData")
        $s_BMPData = StringTrimLeft($s_BMPData, 2);去掉头部"0x"
        _GDIPlus_ImageDispose($hImage)
        _GDIPlus_Shutdown()
        DllCall("psapi.dll", "int", "EmptyWorkingSet", "hWnd", -1)
        ;处理图片数组
        Local $a_return[$i_width][$i_height], $x, $y, $s
        Local $ls = "", $lls = ""
        For $y = $top To $top + $ziHeight - 1;5和4分别是图片上下的空边
                $s = StringMid($s_BMPData, $y * ($i_Stride * 2) + 1, $i_width * 6)
                For $x = $left To $left + $zishu * $ziWidth + ($zishu - 1) * $zhong - 1;6和9分别是图片左右的空边
                        $a_return[$x][$y] = Number("0x" & StringMid($s, $x * 6 + 1, 6))
                        $a_return[$x][$y] = Graycolor($a_return[$x][$y], "blue")
                        If $a_return[$x][$y] < $func_bg Then
                                $a_return[$x][$y] = 1
                        Else
                                $a_return[$x][$y] = 0
                        EndIf
                Next
        Next

        Local $Number = ""
        For $i = 0 To $zishu - 1;读取4个数字的值
                $sx = $left + $ziWidth * $i + $zhong * $i;6是第一个数字的起点,每个数字占9列,第9列是空白列
                For $y = $top To $top + $ziHeight - 1;5和4分别是图片上下的空边
                        $ls = ""
                        For $x = $sx To $sx + $ziWidth - 1;因为每个数字占9列,第9列是空白列,所以只读取8列

                                If $a_return[$x][$y] = 1 Then
                                        $ls &= "1"
                                Else
                                        $ls &= "0"
                                EndIf
                        Next
                        $ls &= "|"
                        $lls = $lls & $ls
                Next
                $Number &= WhatNumber($lls)
                $lls = ""
        Next
        Return $Number

EndFunc   ;==>myYzmShibie

Func WhatNumber($Sum)
        Local $checktotal, $aCheck = StringSplit($Sum, "|")
        For $i = 0 To 9 ;9是数字只有9个
                $checktotal = 0
                For $j = 0 To $ziHeight - 1
                        If $n[$i][$j] <> $aCheck[$j + 1] Then $checktotal += 1
                        If $checktotal > 1 Then ExitLoop
                Next
                If $checktotal < 2 Then Return $i
        Next
        Return -1
EndFunc   ;==>WhatNumber

Func Graycolor($color, $style = "all")
        Local $a_return, $b, $g, $r, $ret
        Switch $style
                Case "blue"
                        $b = BitAND(0xFF, BitShift($color, 16))
                        $a_return = BitOR(BitShift($b, -16), BitShift($b, -8), $b)
                Case "green"
                        $g = BitAND(0xFF, BitShift($color, 8))
                        $a_return = BitOR(BitShift($g, -16), BitShift($g, -8), $g)
                Case "red"
                        $r = BitAND(0xFF, $color)
                        $a_return = BitOR(BitShift($r, -16), BitShift($r, -8), $r)
                Case "all"
                        $b = BitAND(0xFF, BitShift($color, 16))
                        $g = BitAND(0xFF, BitShift($color, 8))
                        $r = BitAND(0xFF, $color)
                        $ret = Int((30 * $r + $g * 59 + $b * 11) / 100)
                        $b = BitAND(0xFF0000, BitShift($ret, -16))
                        $g = BitAND(0x00FF00, BitShift($ret, -8))
                        $r = $ret
                        $a_return = BitOR($b, $g, $r)
        EndSwitch
        Return $a_return
EndFunc   ;==>Graycolor

Func Terminate()
        Exit
EndFunc   ;==>Terminate

austere 发表于 2014-9-25 17:57:40

一直不明白楼主的意思,楼主的意思是要打开这个网站自动填写,然后自动登录吗?

dunphy 发表于 2014-10-11 14:08:45

谢谢。已自行解决,搞定。。。

逆水风帆 发表于 2014-11-24 00:10:30

很给力,支持一下!

olala 发表于 2015-3-5 02:16:32

谢谢。已自行解决,搞定。。。
dunphy 发表于 2014-10-11 14:08 http://www.autoitx.com/images/common/back.gif


    楼主用啥方法解决了,可否过来跟大伙说一下,让大家也学习学习呢。
页: [1]
查看完整版本: 带有一些杂线条的验证码问题【已解决】