内嵌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[10][$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
|