如何登陆12306后,获取下面地址的验证码!
https://dynamic.12306.cn/otsweb/passCodeAction.do?rand=randp 刚才试了一下 不知道为什么不能从ID获取到图片的对象变量, 不过可以直接再下载一次这个验证码 地址可以在源文件里找到 然后用直接用新验证码可以登陆。 回复 2# zch11230给个完整的代码出来试试! 给你一个思路吧,那个我登不上去……#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <IE.au3>
#Include <Clipboard.au3>
#Include <GDIPlus.au3>
$ocrimage = "ocr.bmp"
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 437, 192, 124)
$Pic1 = GUICtrlCreatePic("", 80, 24, 233, 89)
$Button1 = GUICtrlCreateButton("Button1", 104, 176, 209, 49)
$Label1 = GUICtrlCreateLabel("Label1", 104, 272, 292, 129)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
While 1
GUICtrlSetData($Label1," 网页正在加载。")
$oIE=_IECreate("https://dynamic.12306.cn/otsweb/passCodeAction.do?rand=randp",0,0,0,1)
_IELoadWait($oIE,100,10000)
If $oIE = 0 Then
GUICtrlSetData($Label1," 网页加载失败。")
$exitloop = 1
_IEQuit($oIE)
ExitLoop
EndIf
GUICtrlSetData($Label1," 网页成功加载。")
Sleep(1000)
GUICtrlSetData($Label1," 正在获取验证码。")
FileDelete($ocrimage)
$oImg = _IEImgGetCollection ($oIE,0);获取索引0的图片对象
$oPic = $oIE.Document.body.createControlRange()
$oPic.Add($oImg);将图片添加到新创建的集合中(ControlRange)
GUICtrlSetData($Label1," 请修改ie安全设置,使允许访问剪贴板以消除提示。")
$oPic.execCommand("Copy");将集合复制到剪切板
GUICtrlSetData($Label1," 正在获取验证码。")
_GDIPlus_Startup()
_ClipBoard_Open(0)
$iVerifyPics = _ClipBoard_GetDataEx($CF_BITMAP);;从剪贴板获取图片句柄
$iVerifyPics = _GDIPlus_BitmapCreateFromHBITMAP($iVerifyPics);;创建图片
_GDIPlus_ImageSaveToFile ($iVerifyPics, $ocrimage);;;保存图片到当前脚本目录
_ClipBoard_Close()
If FileExists($ocrimage) = 1 Then
GUICtrlSetData($Label1," 验证码获取成功。")
GUICtrlSetImage($pic1,$ocrimage)
ExitLoop
Else
GUICtrlSetData($Label1," 验证码获取失败。")
Sleep(5000)
EndIf
WEnd
EndSwitch
WEnd
学习中,关注中。 论坛上有关于这方面的资料 不太懂POSTS
页:
[1]