无纸化学法用及考试系统(自动登陆及自动答题脚本)
一、自动登陆源码:
说明:这个没什么好说的,查网页元素的ID号,根据ID号填表。
  On Error Resume Next
    s = WebBrowser1.hwnd
    If s > 0 Then ny = MsgBox("如果你没有提交试卷”,请选择。否则,你会没有成绩。" & Chr(13) + Chr(10) & "请提交试卷后再退出本软件!", vbQuestion + vbYesNo, "请提交试卷后再退出本软件")
    If ny = vbNo Then
        SetWindowPos Me.hwnd, -1, 0, 0, 0, 0, 3  '设置窗口总在最前面
    Else
        WebBrowser1.Quit
        Set ie = Nothing
        xlBook.Close (True)
        xlApp.Quit
        Set xlApp = Nothing
        Set dm = Nothing
        Unload Me
    End If
End Sub
Private Sub Command1_Click()
On Error Resume Next '错了断续
'dm.CaptureGif 0, 300, 640, 780, "ss.gif", 100, 20000
If tID.Text <> "" Then
    'Set ie = GetObject("", "InternetExplorer.Application")
    WebBrowser1.Navigate Text1.Text '打开文本框中的网址
    'webbrowser1.WindowState = 1
    Do Until WebBrowser1.ReadyState = 4 '循环直到网址装载完毕
        DoEvents
        j = j + 1
        If j > 65530 Then
            MsgBox "打开无纸学法用法考试网址失败,请联系管理员。"
            Exit Sub
        End If
    Loop
    Delay 500
    WebBrowser1.Document.All("type2").Click  '单击选择普法考试平台
    Delay 200
    WebBrowser1.Document.All("name").Value = tID.Text  '输入登陆用户名
    WebBrowser1.Document.All("password").Value = "888888"  '输入登陆密码
    Delay 100
    WebBrowser1.Document.All.Tags("INPUT")(3).Click  '单击登陆
    Delay 500
    Call InExam   '输入正确,进入下一步
Else
    MsgBox "请输入你的登陆账号!"
    tID.SetFocus
End If
SetWindowPos Me.hwnd, -1, 0, 0, 0, 0, 3  '设置窗口总在最前面

Private Function InExam()
    On Error Resume Next
    dm_ret = dm.FindStr(0, 0, 800, 700, "进入考试", "000000-000000", 1#, intX, intY)
    If intX >= 0 And intY >= 0 Then
         SetCursorPos intX, intY
         mouse_event &H2 Or &H4, 0, 0, 0, 0
    Else
        MsgBox "现在不是考试时间,请联系管理员。"
    End If
    SetWindowPos Me.hwnd, -1, 0, 0, 0, 0, 3  '设置窗口总在最前面
    Delay 800
    dm_ret = dm.FindStr(200, 100, 1024, 800, "开始考试", "006699-000000", 1#, intX, intY)
    If intX >= 0 And intY >= 0 Then
         SetCursorPos intX, intY
         mouse_event &H2 Or &H4, 0, 0, 0, 0
    End If
    dm_ret = dm.SetDict(0, "")
    Delay 800
     dm_ret = dm.FindStr(0, 0, 1024, 600, "确定", "000000-000000", 1#, intX, intY)
    If intX >= 0 And intY >= 0 Then
         SetCursorPos intX + 5, intY + 5
         mouse_event &H2 Or &H4, 0, 0, 0, 0
    End If
    Delay 800
End Function

二、进入考试中心后,接下来就是自动答题了。
说明:1、将题目内容与题库内的题比较,在题库中到题目后,然后将试卷中正确答案前的选择框选择上。(不知道这样说清楚了没有?还是看下面的视频吧)

endFcomp = 0
SetWindowPos Me.hwnd, -1, 0, 0, 0, 0, 3  '设置窗口总在最前面
dm_ret = dm.SetDict(0, "")
dm.UseDict 0
ss:
For Cnt = 1 To 400
    If GetAsyncKeyState(vbKeyEscape) Then Exit For
         If endF = 17 And Fag = 2 Then
            WebBrowser1.Document.parentwindow.scrollby 0, 100
            Delay 10
            dm.WheelDown
            Delay 500
            Label2.Caption = "正在完成判断题的第:18题。"
            dm_ret = dm.FindStr(30, 50, 800, 600, "18", "ff3300-000000", 1#, intX, intY)
            If intX >= 0 And intY >= 0 Then
                s = dm.Ocr(intX + 10, intY - 3, intX + 700, intY + 15, "000000-000000", 1#)
                s = Left(s, Len(s) - 5)
                Call anser2(s, intX + 25, intY)
            End If
            WebBrowser1.Document.parentwindow.scrollby 0, 200
            dm.WheelDown
            Delay 500
            Label2.Caption = "正在完成判断题的第:19题。"
            dm_ret = dm.FindStr(30, 50, 800, 700, "19", "ff3300-000000", 1#, intX, intY)
            If intX >= 0 And intY >= 0 Then
                s = dm.Ocr(intX + 10, intY - 3, intX + 700, intY + 15, "000000-000000", 1#)
                s = Left(s, Len(s) - 5)
                Call anser2(s, intX + 25, intY)
            End If
            WebBrowser1.Document.parentwindow.scrollby 0, 300
            dm.WheelDown
            Delay 500
            Label2.Caption = "正在完成判断题的第:20题。"
            dm_ret = dm.FindStr(30, 50, 800, 800, "20", "ff3300-000000", 1#, intX, intY)
            If intX >= 0 And intY >= 0 Then
                s = dm.Ocr(intX + 10, intY - 3, intX + 700, intY + 15, "000000-000000", 1#)
                s = Left(s, Len(s) - 5)
                Call anser2(s, intX + 25, intY)
            End If
                SetCursorPos 1010, 500
                dm.LeftDown
                SetCursorPos 1010, 300
                dm.LeftUp
                Delay 200
                dm_ret = dm.FindStr(600, 150, 1000, 400, "提交试卷", "103e89-000000", 1#, intX, intY)
                If intX >= 0 And intY >= 0 Then
                    SetCursorPos intX + 10, intY + 3
                    mouse_event &H2 Or &H4, 0, 0, 0, 0
                End If
            WebBrowser1.Document.parentwindow.scrollby 0, -500
            Label2.Caption = "会做的我都做完了,你检查一下,没有做的请你自己完成。记得提交试卷啊。。。"
在线答题系统            SetWindowPos Me.hwnd, -1, 0, 0, 0, 0, 3  '设置窗口总在最前面
            Exit For
         End If
dm_ret = dm.FindStr(30, 50, 800, 600, "", "ff3300-000000", 1#, intX, intY)
    If intX >= 0 And intY >= 0 Then
         s = dm.Ocr(intX, intY - 3, intX + 700, intY + 15, "000000-000000", 1#)
         s = Left(s, Len(s) - 5)
         endF = dm.Ocr(intX - 30, intY - 1, intX - 5, intY + 12, "ff3300-000000", 1#)
         If endF = "" Then
                MsgBox "程序不能正确识别您的电脑,请联系作者:QQ1276652066"
                Exit For
         End If
         If endF = endFcomp Then '是原来的题,向下滚动
            SetCursorPos intX - 30, intY
            mouse_event &H2 Or &H4, 0, 0, 0, 0
            dm.WheelDown
            Delay 500
            GoTo ss:
         End If
         If endFcomp = 40 Then
            'MsgBox "单选题已经完成,下面进入多选题。"
            Fag = Fag + 1
            Set xlBook = Nothing
            Set xlSheet = Nothing
         End If
         'Debug.Print s
         Select Case Fag
         Case 0
            Label2.Caption = "正在完成单选题的第:" & endF & "题。"
            Call anser(s, intX, intY)  '进入单选查答案
         Case 1
            Label2.Caption = "正在完成多选题的第:" & endF & "题。"
            Call anser1(s, intX, intY)  '进入多选查答案
         Case 2
            Label2.Caption = "正在完成判断题的第:" & endF & "题。"
            Call anser2(s, intX, intY)  '进入判断查答案
         End Select
    Else
        MsgBox "不能进入考试,怎么回事??" & Chr(13) + Chr(10) & "请联系本软件作者:QQ1276652066", vbQuestion, "出错了!!"
        Exit For
    End If
    SetCursorPos intX - 30, intY
    mouse_event &H2 Or &H4, 0, 0, 0, 0
    dm.WheelDown
    Delay 500
    endFcomp = endF
Next