|
楼主 |
发表于 2012-8-5 06:52
|
显示全部楼层
cumulonimbus 发表于 2012-8-4 20:42
不好意思,刚才http://user.kdnet.net/login_new.asp试了试,很纳闷,这个网站的验证码比较简单,不知怎么却 ...
凯迪是一个比较反动的网站,如果你有高于常人的主见,浏览一下凯迪是非常有好处的。否则还是不看要好些。
对于这个3534比较特殊,下面是代码:
Public Declare Function GetClipboardData Lib "user32" (ByVal wFormat As Long) As Long
Public Declare Function CloseClipboard Lib "user32" () As Long
Public Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
Public Declare Function GlobalSize Lib "kernel32" (ByVal hMem As Long) As Long
Public Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Public Const CF_TEXT = 1
Public Const CF_BITMAP = 2
Public Const CF_DIB = 8
Sub 验证码识别()
Dim img
Dim CtrlRange
Dim bytClipData() As Byte
Dim arr() As String
Dim b(1 To 30)
Dim c(1 To 30)
Dim a(1 To 4)
Dim tmp()
Dim temp As String
Dim ts As Integer
Cells.Clear
b(1) = ""
b(2) = ""
b(3) = ""
b(4) = "223337"
b(5) = "2233a2"
b(6) = "633335"
b(7) = ""
b(8) = ""
b(9) = ""
b(10) = ""
c(1) = ""
c(2) = ""
c(3) = ""
c(4) = "3"
c(5) = "4"
c(6) = "5"
c(7) = ""
c(8) = ""
c(9) = ""
c(10) = ""
Range("A1:A1").NumberFormatLocal = "@"
On Error Resume Next
With CreateObject("InternetExplorer.application")
.Visible = True
.Navigate "http://club.excelhome.net/thread-896161-4-1.html"
Do Until .ReadyState = 4
DoEvents
Loop
Set img = .Document.All.tags("img")(15)
Set CtrlRange = .Document.body.createControlRange()
CtrlRange.Add img
CtrlRange.execCommand "Copy", True
Dim hMem As Long, lpData As Long
OpenClipboard 0&
hMem = GetClipboardData(8)
If CBool(hMem) Then
lpData = GlobalLock(hMem)
lClipSize = GlobalSize(hMem)
If lpData <> 0 And lClipSize > 0 Then
ReDim bytClipData(0 To lClipSize - 1)
CopyMemory bytClipData(0), ByVal lpData, lClipSize
End If
GlobalUnlock hMem
End If
CloseClipboard
a1 = bytClipData(0)
a2 = bytClipData(4)
a3 = bytClipData(8)
a4 = lClipSize - 40
a5 = a4 / a2 / a3
ReDim arr(1 To a2 * a3)
For i = 1 To a2 * a3
arr(i) = 1
ts = 0
For j = 0 To a5 - 1
ts = ts + Val(bytClipData((i - 1) * a5 + a1 + j))
Next j
ts = ts / a5
If ts > 200 Then
arr(i) = ""
End If
Next i
For i = 1 To a3
For j = 1 To a2
Cells(a3 + 1 - i, j) = arr((i - 1) * a2 + j)
Next j
Next i
temp = ""
For i = 1 To a2
For j = 1 To a3
Cells(a3 + 1, i) = Cells(a3 + 1, i) + arr((j - 1) * a2 + i)
Next j
If Cells(a3 + 1, i) = 10 Then Cells(a3 + 1, i) = "a"
If Cells(a3 + 1, i) <> "" Then
temp = temp & Cells(a3 + 1, i)
Else
temp = temp & ","
temp = Replace(temp, ",,", ",")
End If
Next i
Cells.Clear
For j = 1 To 10
temp = Replace(temp, b(j), c(j))
Next j
Cells(1, 1) = Format(Replace(temp, ",", ""), "0000")
.Quit
End With
End Sub
|
|