#NoTrayIcon
#include <IE.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
Global $src_img, $src_HTML, $oItem, $id = 0
Local $oIE = _IECreateEmbedded()
$hGui = GUICreate("Embedded Web control Test", 640, 580, _
(@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _
$WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)
GUISetOnEvent($GUI_EVENT_CLOSE, "GUI_SetState")
While 1
$str = ClipGet()
$Code = StringRegExpReplace($str, '(?ims).*?提取码:(\w{4}).*?[\s\n]+?复制.*', '$1')
$Link = StringRegExpReplace($str, '(?ims).*?链接:.*(https:)(.*?)[\s\n\W]+?提取码.*', '$1$2')
If StringInStr($Link, 'https://pan.baidu.com/s') And StringLen($Code) = 4 Then AutoExits_Download()
WEnd
Func GUI_SetState()
GUISetState(@SW_HIDE, $hGui)
EndFunc ;==>GUI_SetState
Func AutoExits_Download()
ClipPut('')
MsgBox(64 + 262144, "提示", "您已复制提取码。3 秒后将开始下载!", 1)
GUICtrlCreateObj($oIE, 10, 40, 600, 360)
_IENavigate($oIE, $Link) ;文件夹
Local $oForm = _IEFormGetObjByName($oIE, "accessForm")
$ele_Input = _IEFormElementGetObjByName($oForm, "rrxevJ5B")
_IEFormElementSetValue($ele_Input, $Code)
_IELinkClickByText($ele_Input, "提取文件")
Do
$BodyText = $oIE.document.body.innerHTML
Until StringInStr($BodyText, "下载") ;读取网页body部份的HTML,直到含有给的代码
$Match = StringRegExp($BodyText, '(?U)span.*>(下载.*)</span>.*', 1)
If $Match <> 0 Then
If $Match[0] <> '下载' Then
_IELinkClickByText($oIE, $Match[0])
AdlibRegister('CheckError',500)
$id = 1
Else
Local $oItems = _IETagNameGetCollection($oIE, "span")
For $oItem In $oItems
_IEAction($oItem, 'click')
$src = _IEDocReadHTML($oItem)
If StringInStr($src, "EzubGg") Then
_IELinkClickByText($oIE, $Match[0])
AdlibRegister('CheckError',500)
ExitLoop
EndIf
Next
EndIf
EndIf
EndFunc ;==>AutoExits_Download
Func CheckError()
$src_HTML = _IEDocReadHTML($oIE)
If StringInStr($src_HTML, "请输入验证码") Then
AdlibUnRegister('CheckError')
MsgBox(64 + 262144, "提示", "本次下载需要手动输入验证码!")
GUISetState(@SW_SHOW, $hGui)
$id = 1
ElseIf StringInStr($src_HTML, "请点击下载") Then
AdlibUnRegister('CheckError')
_IELinkClickByText($oIE, '立即下载')
$hTimer = TimerInit() ; Begin the timer and store the handle in a variable.
While 1
If WinExists('文件下载', '你要打开还是保存此文件?') Or TimerDiff($hTimer) > 1000 * 5 Then
WinSetOnTop('文件下载', '你要打开还是保存此文件?', 1)
$id = 1
ExitLoop
EndIf
Sleep(250)
WEnd
EndIf
If WinExists('设置下载存储路径') Then
AdlibUnRegister('CheckError')
$id = 1
EndIf
EndFunc ;==>CheckError