#Persistent ; 为了进行演示, 当用户选择 "No" 时让脚本持续运行. SetWorkingDir %A_ScriptDir% ; 脚本当前工作目录 z前脚本所在目录的绝对路径. 不包含最后的反斜线(根目录同样如此)。;~ MsgBox,% A_ScriptDir ;A_ScriptDir指的是D:portableAutoHotkey OnExit, ExitSub Gui, Add, Text, x5 y10 h30 , 请输入链接 Gui, Add, Edit, x+10 y10 w380 h30 vedit1 ,http://t.cn/RUnHdsx Gui, Add, Text, x5 y65 h30 , 间隔时间 Gui, Add, Edit, x+20 y60 w80 h30 vedit2,5 Gui, Add, Text, x+10 y65 h30, ID Gui, Add, Edit, x+10 y60 w80 h30 vedit3,48 Gui, Add, Text, x+10 y65 h30, 循环次数, Gui, Add, Edit, x+10 y60 w80 h30 vedit4,33 Gui, Add, Button, x70 y100 w100 h40 , 开始F6 Gui, Add, Button, x+20 y100 w100 h40 , 暂停F7 Gui, Add, Button, x+20 y100 w100 h40 , 结束F8 ;~ Gui, Show, w764 h480, Untitled GUI Gui, Show, , %A_ScriptName% return f7:: Button暂停F7: Pause return f8:: Button结束F8: ExitApp return f6:: Button开始F6: Gui Submit,NoHide pwb := ComObjCreate("InternetExplorer.Application") ; Create an IE object pwb.Visible := True ; Make the IE object visible Loop,%edit4% { count:=A_Index ;~ pwb := ComObjCreate("InternetExplorer.Application") ; Create an IE object ;~ pwb.Visible := True ; Make the IE object visible ;~ pwb.Navigate("http://task.qbao.com") pwb.Navigate(edit1) Loop { ;等待网页加载完成! Sleep,200 if (pwb.ReadyState="complete" or pwb.ReadyState=4 or A_LastError!=0) break } ;****** ;获取元素的值 ;~ msgbox % ie.document.all(48).innertext ;获取innertext的值 ;~ msgbox % pwb.document.all(48).href ;获取href的值 ;~ msgbox % ie.document.GetElementsByTagName("A").item(2).href ;获取href的值,跟上面的方法达到的效果一样 Loop, { WinGetTitle, OutputVar, ahk_class IEFrame ;~ Internet Explorer 无法显示该网页 - Windows Internet Explorer ;~ ahk_class IEFrame ;~ ahk_exe IEXPLORE.EXE if (OutputVar="Internet Explorer 无法显示该网页 - Windows Internet Explorer") { ;~ MsgBox 网页没加载完毕 SoundPlay, %A_ScriptDir%err.wav ;任务出错 ControlSend, edit1, +{Enter}, ahk_class IEFrame ;~ pwb.Navigate(edit1) Sleep 1000 Loop { ;等待网页加载完成! Sleep,200 if (pwb.ReadyState="complete" or pwb.ReadyState=4 or A_LastError!=0) break } ;****** if A_Index=2 { ;~ msgbox 请链接网络 Send,^!d WinWaitActive,连接 ADSL ahk_class #32770,,8 Sleep 500 ControlClick,Button4,连接 ADSL ahk_class #32770 ;先获取标题,然后点击相应的按钮 WinWaitNotActive,ahk_class #32770,,8 Sleep 500 ;~ continue } continue } break } ;~ anniu:=pwb.document.all(48).href ;~ anniu=pwb.document.all(%edit3%).href ;~ MsgBox %anniu% ;点击元素 ;~ pwb.document.all(48).click() ;点击按钮 pwb.document.all(edit3).Click() ;点击按钮 ;~ pwb.document.GetElementsByTagName("A").item(2).Click() ;点击按钮,跟上面的方法达到的效果一样 TrayTip, 已刷次数, % "已刷" . A_Index . "次,剩余" . edit4-A_Index . "次" Sleep 500 an := ComObjCreate("InternetExplorer.Application") ; Create an IE object an.Visible := True ; Make the IE object visible ;~ an.Navigate(anniu) ;---------------------------------------------------------------------------------------- an.Navigate(pwb.document.all(48).href) ;---------------------------------------------------------------------------------------- Loop { ;等待网页加载完成! Sleep,200 if (an.ReadyState="complete" or an.ReadyState=4 or A_LastError!=0) break } ;****** Loop, { WinGetTitle, OutputVar, ahk_class IEFrame if (OutputVar="Internet Explorer 无法显示该网页 - Windows Internet Explorer") { SoundPlay, %A_ScriptDir%err.wav ;任务出错 ControlSend, edit1, +{Enter}, ahk_class IEFrame Sleep 1000 Loop { ;等待网页加载完成! Sleep,200 if (pwb.ReadyState="complete" or pwb.ReadyState=4 or A_LastError!=0) break } ;****** if A_Index=3 { MsgBox 请检查浏览器 ;~ continue } continue } break } TrayTip, 已刷次数, % "已刷" . A_Index . "次,剩余" . edit4-A_Index . "次" shijian:=edit2*1000 Sleep % shijian ;~ winclose ahk_class IEFrame WinClose ahk_exe iexplore.exe Sleep 500 ;~ WinClose ahk_exe iexplore.exe pwb.Navigate("about:blank") ;导航至about:blank,节省内存 Sleep 500 Send,^!d ;~ WinWaitActive,ahk_class #32770,,8 WinWaitActive,ADSL 状态 ahk_class #32770,,8 ;~ sleep 500 ;~ Send !d ;~ WinGetTitle, zTitle, A ;~ ControlClick,Button4,%zTitle% ;先获取标题,然后点击相应的按钮 ControlClick,Button4,ADSL 状态 ahk_class #32770 ;先获取标题,然后点击相应的按钮 ;~ Button4 ;~ ADSL 状态 ahk_class #32770 ;~ ahk_exe Explorer.EXE WinWaitNotActive,ADSL 状态 ahk_class #32770,,8 Sleep 500 Send,^!d WinWaitActive,连接 ADSL ahk_class #32770,,8 Sleep 500 ;~ ControlClick,Button4,%zTitle% ;先获取标题,然后点击相应的按钮 ControlClick,Button4,连接 ADSL ahk_class #32770 ;先获取标题,然后点击相应的按钮 ;~ Send !c ;~ Button4 ;~ 连接 ADSL ahk_class #32770 ;~ ahk_exe Explorer.EXE WinWaitNotActive,ahk_class #32770,,8 Sleep % shijian ;~ 正在连接 ADSL... ;~ WinWaitnotActive ahk_exe Explorer.EXE TrayTip, 已刷次数, % "已刷" . A_Index . "次,剩余" . edit4-A_Index . "次" } return GuiClose: ExitApp return ExitSub: Gui Submit,NoHide ;~ MsgBox % count ;~ MsgBox % "已刷" . A_Index . "次,剩余" . edit4-A_Index . "次" MsgBox % "已刷" . count . "次,剩余" . edit4-count . "次" ExitApp return