百度云盘复制分享链接自动下载
本帖最后由 Mixrelax 于 2020-6-25 22:12 编辑#include <IE.au3>
#include <Inet.au3>
#include <Misc.au3>
#include <GUIConstantsEx.au3>
If _Singleton("BaiduNetDisk", 1) = 0 Then Exit
Opt("GUIOnEventMode", 1)
Opt("TrayMenuMode", 1)
Global $hGui = GUICreate("Form1", 500, 400, -1, -1)
Global $oIE = ObjCreate("Shell.Explorer.2")
GUISetOnEvent($GUI_EVENT_CLOSE, "GUI_SetState")
GUISetState(@SW_SHOW)
Func GUI_SetState()
Exit
EndFunc ;==>GUI_SetState
While 1
Sleep(450)
$str = ClipGet()
$Code = StringRegExpReplace($str, '(?ims).*?提取码.*[:|:]?.*(\w{4}).*', '$1')
$Link = StringRegExpReplace($str, '(?ims).*?链接.*[:|:].*(https:)(.*?)[\s\n\W]+?提取码.*', '$1$2')
If StringInStr($Link, 'https://pan.baidu.com/s') And StringLen($Code) = 4 Then AutoDownload()
WEnd
Func AutoDownload()
ClipPut('')
ToolTip("您已复制分享链接,3-5 秒后将开始下载!")
$Obj1_ctrl = GUICtrlCreateObj($oIE, 0, 0, 480, 380)
_IENavigate($oIE, $Link) ;文件夹
Local $oForm = _IEFormGetObjByName($oIE, "accessForm")
$src_HTML = _INetGetSource($Link)
$id = StringRegExpReplace($src_HTML, '(?ims).*?<input class=.*?id="(.*?)".*type="text">.*', '$1')
$ele_Input = _IEFormElementGetObjByName($oForm, $id)
_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 <> '下载' Then
Sleep(500)
_IELinkClickByText($oIE, $Match)
ToolTip('')
AdlibRegister('CheckError', 500)
Else
Local $oItems = _IETagNameGetCollection($oIE, "span")
For $oItem In $oItems
_IEAction($oItem, 'click')
$src = _IEDocReadHTML($oItem)
If StringInStr($src, "EzubGg") Then
_IELinkClickByText($oIE, $Match)
ToolTip('')
Sleep(500)
AdlibRegister('CheckError', 500)
ExitLoop
EndIf
Next
EndIf
EndIf
EndFunc ;==>AutoDownload
Func CheckError()
$src_HTML = _IEDocReadHTML($oIE)
If StringInStr($src_HTML, "请输入验证码") Then
AdlibUnRegister('CheckError')
MsgBox(64 + 262144, "提示", "本次下载需要手动输入验证码!")
ElseIf StringInStr($src_HTML, "请点击下载") Then
AdlibUnRegister('CheckError')
_IELinkClickByText($oIE, '立即下载')
$hTimer = TimerInit()
While 1
If WinExists('文件下载', '你要打开还是保存此文件?') Or TimerDiff($hTimer) > 1000 * 5 Then
ToolTip('')
WinSetOnTop('文件下载', '你要打开还是保存此文件?', 1)
ExitLoop
EndIf
Sleep(250)
WEnd
EndIf
If WinExists('设置下载存储路径') Then
AdlibUnRegister('CheckError')
EndIf
EndFunc ;==>CheckError
首次登陆百度网盘账号时会报错,第二次当浏览器自动记住Cookie后下次就不会报错了。需要注意的是此辅助工具需要配合百度网盘客户端使用
页:
[1]