本帖最后由 rolaka 于 2010-9-22 23:06 编辑
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <ie.au3>
Global $data[1]
referData()
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 1001, 447, 192, 124)
$Group1 = GUICtrlCreateGroup("Group1", 744, 10, 241, 345)
$Edit1 = GUICtrlCreateEdit("", 760, 32, 209, 305, BitOR($ES_AUTOHSCROLL, $ES_WANTRETURN, $WS_VSCROLL))
GUICtrlSetData(-1, "Edit1")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("Button1", 744, 368, 241, 65)
$oIE = _IECreateEmbedded()
$ActiveX = GUICtrlCreateObj($oIE, 16, 16, 708, 418)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
_IENavigate($oIE, "http://wmzsjs.eastday.com/channel/game2/register.asp")
;~ _IEDocWriteHTML($oIE, FileRead("2"))
While 1
_IELoadWait($oIE)
$oDoc = _IEDocGetObj($oIE)
If StringInStr($oDoc.url, "answer.asp") Then
;~ MsgBox(0, "setp", "1")
$test = _IEBodyReadHTML($oIE)
;~ FileWrite("2", $test)
If StringRight($test, 1) <> "1" Then
;~ MsgBox(0, "setp", "2")
_IEBodyWriteHTML($oIE, $test & "1")
$answer = StringRegExp($test, "<SPAN class=STYLE8>\s*(.+)\s+</SPAN>", 3)
;~ _ArrayDisplay($answer)
If @error <> 0 Then
;~ MsgBox(0, "", @error)
_ArrayDisplay($answer)
EndIf
$key = searchAnswer($answer[0])
$flag = 0
;~ MsgBox(0, "", $key)
If $key <> "" Then
;~ MsgBox(0, "setp", "3")
;~ MsgBox(0, "", $key)
For $i = 1 To UBound($answer)
;~ MsgBox(0, StringInStr($answer[$i], $key), $answer[$i]&" "&$key)
If StringInStr($answer[$i], $key) Then
;~ If StringInStr($answer[$i], $key) And (StringLen($answer[$i])-StringLen($key)) < 10 Then
$htmlName = StringRegExp($test, 'value=(\d+) type=radio name=ChkAns> </TD>\s+<TD width="97%"><SPAN class=STYLE8>.+?' & $key, 3)
If @error <> 0 Then
$flag = 2
ExitLoop
Else
$flag = 0
$oForm = _IEFormGetObjByName($oIE, "AnswerForm")
_IEFormElementRadioSelect($oForm, $htmlName[0], "ChkAns", 1)
_IENavigate($oIE, "javascript:checkForm()", 1)
MsgBox(0, $htmlName[0], $htmlName[0])
ExitLoop
EndIf
EndIf
Next
Else
$flag = 1
EndIf
If $flag Then
MsgBox(0, "检索失败", "请手动答题...")
EndIf
EndIf
EndIf
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
referData()
EndSwitch
WEnd
Func searchAnswer($answer)
;~ $index = _ArraySearch($data, clearVal($answer), 0, 0, 0, 0, 0, 1)
For $i = 0 To UBound($data) - 1
ConsoleWrite($data[$i][0] & "|" & $answer & "|" & StringInStr(clearVal($answer), $data[$i][0]) & "|" & @CRLF)
If StringInStr($data[$i][0], clearVal($answer)) Or StringInStr(clearVal($answer), $data[$i][0]) Then
Return clearVal($data[$i][1])
EndIf
Next
Return ""
EndFunc ;==>searchAnswer
Func clearVal($val)
Return StringStripWS($val, 3)
EndFunc ;==>clearVal
Func referData()
$fp = FileOpen("data.txt")
Global $data[1]
While 1
$line = FileReadLine($fp)
If @error <> 0 Then
ExitLoop
EndIf
$key = StringSplit($line, "|", 2)
$index = UBound($data)
ReDim $data[$index + 1][2]
$data[$index][0] = $key[0]
$data[$index][1] = $key[1]
WEnd
_ArrayDelete($data, 0)
EndFunc ;==>referData
=.= 以前写的 测试版 实际用还有点小问题...
很乱...填写身份证信息 -(提交)-> 当地址里包含answer.asp时候 匹配题目+搜索答案+匹配正确项的name -(选择正确的项目+提交表单)-> 等待加载完毕 返回第二步
后面答题完毕了之后处理的部分没有写 因为从来就没能正常答到最后..............................................
附件是题库 |