Board logo

标题: [问题求助] 怎么用vbs识别图片数字验证码? [打印本页]

作者: Roxx    时间: 2024-5-18 12:57     标题: 怎么用vbs识别图片数字验证码?

网页注册账号,以前没有验证码,现在加了验证码 用vbs怎么才能实现识别验证码

我按照下面的代码识别这个 为啥识别不了,怎么样才能实现识别验证码
  1. Option Explicit
  2. '要识别的图片名称
  3. Dim picName
  4. picName = "1.jpg"
  5. '数字对照表,识别图片时就是把从图片提取的与该数组比较,相同的便是该数字
  6. Dim NumAry(9)
  7. NumAry(0)="00011000001111000110011011000011110000111100001111000011011001100011110000011000"
  8. NumAry(1)="00011000001110000111100000011000000110000001100000011000000110000001100001111110"
  9. NumAry(2)="00111100011001101100001100000011000001100000110000011000001100000110000011111111"
  10. NumAry(3)="01111100110001100000001100000110000111000000011000000011000000111100011001111100"
  11. NumAry(4)="00000110000011100001111000110110011001101100011011111111000001100000011000000110"
  12. NumAry(5)="11111110110000001100000011011100111001100000001100000011110000110110011000111100"
  13. NumAry(6)="00111100011001101100001011000000110111001110011011000011110000110110011000111100"
  14. NumAry(7)="11111111000000110000001100000110000011000001100000110000011000001100000011000000"
  15. NumAry(8)="00111100011001101100001101100110001111000110011011000011110000110110011000111100"
  16. NumAry(9)="00111100011001101100001111000011011001110011101100000011010000110110011000111100"
  17. Dim st,dataOff,imgW,imgH,imgWBytes,unitW,unitH
  18. Set st = Wscript.createobject("ADODB.Stream")
  19. st.Type = 1
  20. st.Mode = 3
  21. st.open()
  22. '加载图片二进制流,并读取图片头信息
  23. st.LoadFromFile(picName)
  24. st.position = 10
  25. '获取数据偏移
  26. dataOff = BinVal(st.read(4))
  27. st.read(4)
  28. '图片宽、高(象素)
  29. imgW = BinVal(st.read(4))
  30. imgH = BinVal(st.read(4))
  31. imgWBytes = imgW
  32. '每个数字的宽、高(象素)
  33. unitW = 8
  34. unitH = 10
  35. MsgBox st.LoadFromFile(picName)
  36. MsgBox dataOff
  37. MsgBox imgW&vbCrLf&imgH
  38. Dim i,ii,tmp,validCode
  39. '循环获取五个数字
  40. For i=0 To 4
  41. '获取某数字的特征,并与对照表进行比较,找到对应的则记录,否则以*号标识
  42. '3188是第一个数字的左上角的数据偏移,每向后一个则偏移增加 unitW+1
  43. tmp = getBound(3188+(unitW+1)*i)
  44. For ii=0 To 9
  45. If tmp = NumAry(ii) Then
  46. validCode = validCode & ii
  47. Exit For
  48. End If
  49. Next
  50. If Len(validCode) = i Then validCode = validCode & "*"
  51. Next
  52. '关闭
  53. st.Close()
  54. Set st = Nothing
  55. '程序完成
  56. MsgBox("验证码是:"&validCode)
  57. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  58. '获取指定矩形区域的特征码
  59. 'bp:矩形左上角的偏移 unitW:矩形宽 unitH:矩形高
  60. '按照矩形图形从左到右、从上到下的方向进行提取,如该点二进制为1则表示为1,否则为0
  61. Function getBound(bp)
  62. Dim str,i,ii
  63. st.Position = bp
  64. For i=1 To unitH
  65. For ii=1 To unitW
  66. If AscB(st.Read(1)) = 1 Then
  67. str = str & "1"
  68. Else
  69. str = str & "0"
  70. End If
  71. Next
  72. st.Position = bp - i*imgWBytes
  73. Next
  74. getBound = str
  75. End Function
  76. '将2进制转化为数字
  77. Function BinVal(bin)
  78. dim ret
  79. ret = 0
  80. for i = lenb(bin) to 1 step -1
  81. ret = ret *256 + ascb(midb(bin,i,1))
  82. next
  83. BinVal=ret
  84. End Function
  85. Rem 将字符转换成2进制数组的函数
  86. function ASCIIToByteArray(sText)
  87. Dim objRS
  88. Dim lTemp
  89. Dim sTemp
  90. sTemp = ""
  91. For lTemp = 1 to LenB(sText)
  92. sTemp = sTemp & Right("00" & Hex(AscB(MidB(sText,lTemp,1))),2)
  93. Next
  94. set objRS = WScript.CreateObject("ADODB.Recordset")
  95. objRS.Fields.Append "Temp",204,LenB(sText)+1
  96. objRS.Open
  97. objRS.AddNew
  98. objRS("Temp") = sTemp ' ADODB will convert here
  99. objRS.Update
  100. objRS.MoveFirst
  101. ASCIIToByteArray = objRS("Temp") ' A variant byte array is returned
  102. objRS.Close
  103. set objRS = Nothing
  104. end function
复制代码

作者: jyswjjgdwtdtj    时间: 2024-5-18 13:24

网上找个免费的ai的api 识别个简单验证码还是可以的
作者: Roxx    时间: 2024-5-18 18:01

回复 2# jyswjjgdwtdtj


    不会啊。。。




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2