_regist_baidu()
Func _regist_baidu()
Local $registbaiduok = 0
Local $winregist= GUICreate("注册百度账号", 400, 350, -1, -1)
Local $oIE = _IECreateEmbedded()
Local $GUIActiveX = GUICtrlCreateObj($oIE, -70, -130, 690, 650);嵌入ie控件
_IENavigate($oIE, "https://passport.baidu.com/v2/?reg&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2F", 1) ;注册链接
GUISetState(@SW_SHOW)
Local $oQuery1 = _IEGetObjById ( $oIE, "pass_reg_email_0")
$oQuery1.value = "a1s2d3f4g5@126.com"
_IEAction ( $oQuery1, "focus" )
Sleep(50)
Local $oQuery2 = _IEGetObjById ( $oIE, "pass_reg_username_0")
$oQuery2.value = "a1s2d3f4g5"
_IEAction ( $oQuery2, "focus" )
Sleep(50)
Local $oQuery5 = _IEGetObjById ( $oIE, "pass_reg_password_0")
$oQuery5.value = "a1s2d3f4g5"
_IEAction ( $oQuery5, "focus" )
Sleep(50)
Local $oQuery6 = _IEGetObjById ( $oIE, "pass_reg_repassword_0")
$oQuery6.value = $password
_IEAction ( $oQuery6, "focus" )
Sleep(50)
Local $verifycode = _get_verifycode_baidu($oIE) ;获取验证码
Local $oQuery3 = _IEGetObjById ( $oIE, "pass_reg_verifycode_0")
$oQuery3.value = $verifycode
_IEAction ( $oQuery3, "focus" )
Sleep(50)
Local $oQuery4 = _IEGetObjById ( $oIE, "pass_reg_submit_0")
_IEAction ( $oQuery4, "focus" )
_IEAction ( $oQuery4, "click" )
_IELoadWait($oIE)
GUIDelete($winregist)
EndFunc
Func _get_verifycode_baidu($oIE)
Local $gettimes = 0
Local $iVerifyPic, $iVerifyPics, $winverify, $pic_verify, $input_verify, $button_verify_ok, $msg, $verifycode
Local $verifyimgfile = @TempDir & "\baiduregistverifyimg.jpg"
Local $verifypicfile = @TempDir & "\baiduregistcontrolpic.jpg"
While 1
If $gettimes > 100 Then
Return 0
Else
$iVerifyPic = _IEImgGetCollection($oIE, 1)
_GDIPlus_Startup()
$iVerifyPics = $oIE.Document.body.createControlRange()
$iVerifyPics.add($iVerifyPic)
$iVerifyPics.Select()
$iVerifyPics.execCommand('Copy')
Sleep(100)
_ClipBoard_Open(0)
$iVerifyPics = _ClipBoard_GetDataEx($CF_BITMAP)
$iVerifyPics = _GDIPlus_BitmapCreateFromHBITMAP($iVerifyPics)
_ClipBoard_Close()
FileDelete($verifyimgfile)
_GDIPlus_ImageSaveToFile($iVerifyPics, $verifyimgfile)
If FileGetSize($verifyimgfile) <> FileGetSize($verifypicfile) Then
FileCopy($verifyimgfile, $verifypicfile, 9)
$winverify = GUICreate("验证码-百度", 133, 88, -1, -1,-1,-1)
$pic_verify = GUICtrlCreatePic("", 0, 0, 130, 53, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
GUICtrlSetImage($pic_verify, $verifypicfile)
$input_verify = GUICtrlCreateInput("", 2, 56, 68, 28,$ES_CENTER)
$button_verify_ok = GUICtrlCreateButton("确定", 72, 56, 57, 29)
GUISetState(@SW_SHOW)
Opt("GUIOnEventMode", 0)
While 1
If StringLen(GUICtrlRead($input_verify)) == 4 Then ExitLoop
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then
ExitLoop
ElseIf $msg = $button_verify_ok Then
ExitLoop
EndIf
WEnd
Opt("GUIOnEventMode", 1)
$verifycode = GUICtrlRead($input_verify)
GUIDelete ( $winverify )
Return $verifycode
Else
Sleep(100)
$gettimes += 1
EndIf
EndIf
WEnd
EndFunc ;==>_get_verifycode_baidu
以上是注册百度帐号的例子,代码不完整,仅供参考。可以从中看到验证码图片获取方法及验证码输入方法。