在Autoit上获取ReCaptcha图像



我正在尝试制作一个自动在网页中注册的机器人程序(在Autoit中)。我在尝试重新捕获图像时遇到了问题。我使用以下代码

$imgCaptchaId = _IEGetObjById($oForm,"recaptcha_challenge_image")
   $imgCaptcha = $imgCaptchaId.src
   Local $sFile
   GUICreate("Captcha Image",400,200)
   $sFile = _GetURLImage($imgCaptcha, @TempDir & "Captcha.jpg")
   GUICtrlCreatePic($sFile,0,0,300,100)
   GUISetState(@SW_SHOW)
   Sleep(3000)
EndFunc

Func _GetURLImage($sURL, $sDirectory = @ScriptDir)
    Local $hDownload, $sFile
    $sFile = StringRegExpReplace($sURL, "^.*/", "")
    If @error Then
        Return SetError(1, 0, $sFile)
    EndIf
    If StringRight($sDirectory, 1) <> "" Then
        $sDirectory = $sDirectory & ""
    EndIf
    $sDirectory = $sDirectory & $sFile
    If FileExists($sDirectory) Then
        Return $sDirectory
    EndIf
    $hDownload = InetGet($sURL, $sDirectory, 17, 1)
    While InetGetInfo($hDownload, 2) = 0
        If InetGetInfo($hDownload, 4) <> 0 Then
            InetClose($hDownload)
            Return SetError(1, 0, $sDirectory)
        EndIf
        Sleep(105)
    WEnd
    InetClose($hDownload)
    Return $sDirectory
EndFunc   ;==>_GetURLImage

这是网络源的一部分

<div class="col-sm-9">
                <script type="text/javascript">
var RecaptchaOptions = {lang:'en'};
</script>
<script type="text/javascript" src="http://api.recaptcha.net/challenge?k=6Lef6gAAAAAAAPvrfh4xDy4hU4HwxNntiEtiMiNv"></script><script type="text/javascript" src="http://www.google.com/recaptcha/api/js/recaptcha.js"></script><div class=" recaptcha_nothad_incorrect_sol recaptcha_isnot_showing_audio" id="recaptcha_widget_div" style=""><div id="recaptcha_area"><table id="recaptcha_table" class="recaptchatable recaptcha_theme_red"> <tbody><tr> <td colspan="6" class="recaptcha_r1_c1"></td> </tr> <tr> <td class="recaptcha_r2_c1"></td> <td colspan="4" class="recaptcha_image_cell"><center><div style="width: 300px; height: 57px;" id="recaptcha_image"><img id="recaptcha_challenge_image" alt="reCAPTCHA challenge image" src="http://www.google.com/recaptcha/api/image?c=03AHJ_Vuv4Mq74aHE4GEYjHM22aHn5iq3BQrKDotZtRap-Ob5LQ1n84PxmJLJdUzbtfw__CumJ7PMfuP6LYOkTIstU3cdw06Q0cLql9Mn-bZTrs4fckUOs3yq8HYidNXztsqq3AZbgF0a2SbKCNKpTkc7bhZxetwUvl2fdlIYbKeAVMoMuJleaB_anXWnPKtPwQqm-EzEX4f9o-b-TtE4JzI9TtkARnZ7f6qeP5klty4UQDAtQ3yw7lVrf_qnr4jFSz93TOMn3li2GVl8VTgiX75Stn8AljBRShg&amp;th=,CPmw1sTBQJgvckO25-wfSWNrWzDwAAAAsKAAAAAn2ADbfVjn_jg9HiajEe1G7myZuX88pWoDQy2COTvhzKRPbGBLzAxtSMy2pxZVajAMmwJvZMYoltM0ZCEGJ9WbDOnRGmZ6TUIpx17CTXRv2chm82-LE__ZTd1dTA9838egbW1zl2KiQDpm99NHA63o18YRM9Ee_Z4fcFTL-iFel2cDKck89wh8VnlTYCjcLapzdD9Eq44xOeYlb3VlKgiZvQ3sQfbaSaC3wH-gG1ziidF4wbBzIMgkrclgUgYyI5HtO66J1ivYxGLOM-weUM9EJQDlpwdT8vEBKRoSxH-J" height="57" width="300"></div></center></td> <td class="recaptcha_r2_c2"></td> </tr> <tr> <td rowspan="6" class="recaptcha_r3_c1"></td> <td colspan="4" class="recaptcha_r3_c2"></td> <td rowspan="6" class="recaptcha_r3_c3"></td> </tr> <tr> <td rowspan="3" class="recaptcha_r4_c1" height="49"> <div class="recaptcha_input_area"> <span style="display: none;" id="recaptcha_challenge_field_holder"><input name="recaptcha_challenge_field" id="recaptcha_challenge_field" value="03AHJ_Vuv4Mq74aHE4GEYjHM22aHn5iq3BQrKDotZtRap-Ob5LQ1n84PxmJLJdUzbtfw__CumJ7PMfuP6LYOkTIstU3cdw06Q0cLql9Mn-bZTrs4fckUOs3yq8HYidNXztsqq3AZbgF0a2SbKCNKpTkc7bhZxetwUvl2fdlIYbKeAVMoMuJleaB_anXWnPKtPwQqm-EzEX4f9o-b-TtE4JzI9TtkARnZ7f6qeP5klty4UQDAtQ3yw7lVrf_qnr4jFSz93TOMn3li2GVl8VTgiX75Stn8AljBRShg" type="hidden"></span><input autocomplete="off" name="recaptcha_response_field" id="recaptcha_response_field" autocorrect="off" autocapitalize="off" placeholder="Type the text" type="text"> <span id="recaptcha_privacy" class="recaptcha_only_if_privacy"><a target="_blank" href="http://www.google.com/intl/en/policies/">Privacy &amp; Terms</a></span> </div> </td> <td rowspan="4" class="recaptcha_r4_c2"></td> <td><a title="Get a new challenge" id="recaptcha_reload_btn"><img alt="Get a new challenge" src="http://www.google.com/recaptcha/api/img/red/refresh.gif" id="recaptcha_reload" height="17" width="25"></a></td> <td rowspan="4" class="recaptcha_r4_c4"></td> </tr> <tr> <td><a title="Get an audio challenge" id="recaptcha_switch_audio_btn" class="recaptcha_only_if_image"><img src="http://www.google.com/recaptcha/api/img/red/audio.gif" id="recaptcha_switch_audio" alt="Get an audio challenge" height="16" width="25"></a><a title="Get a visual challenge" id="recaptcha_switch_img_btn" class="recaptcha_only_if_audio"><img src="http://www.google.com/recaptcha/api/img/red/text.gif" id="recaptcha_switch_img" alt="Get a visual challenge" height="16" width="25"></a></td> </tr> <tr> <td><a title="Help" id="recaptcha_whatsthis_btn"><img alt="Help" src="http://www.google.com/recaptcha/api/img/red/help.gif" id="recaptcha_whatsthis" height="16" width="25"></a></td> </tr> <tr> <td class="recaptcha_r7_c1"></td> <td class="recaptcha_r8_c1"></td> </tr> </tbody></table> </div></div>
            </div>

有人能帮我吗?

不需要复杂的下载功能。

$CaptchaFile = @TempDir & "Captcha.jpg"
$imgCaptchaId = _IEGetObjById($oForm,"recaptcha_challenge_image")
$imgCaptcha = $imgCaptchaId.src
GUICreate("Captcha Image",400,200)
FileDelete($CaptchaFile)
InetGet($imgCaptcha, $CaptchaFile)
GUICtrlCreatePic($CaptchaFile,0,0,300,100)
GUISetState(@SW_SHOW)

如果您仍然想使用该函数,请确保GetURLImage返回的是正确的内容。现在它看起来像它的返回目录,但您需要一个完整的文件路径。这个功能一团糟。我打赌问题就在那里。

相关内容

  • 没有找到相关文章

最新更新