BinaryBrother Posted March 26, 2009 Share Posted March 26, 2009 (edited) Hey guys!I have a tough one today, for me anyway. I have 2 problems with this code, and I've looked it over until I'm blue in the face, and I'm stuck.1st:_IELoadWait() never returns, it waits forever for the page to load, even though it's already loaded... But if I click somewhere in the page, it returns and moves on, debugging shows that it is hanging somewhere inside the IE.au3 UDF. Is this a bug maybe? Or just bad syntax?The _IECreate() on line 157, is the one that is never returning. I stated _IELoadWait() earlier because by what I understand, this is called automatically if the flag is set properly in _IECreate(). I have tried telling the _IECreate() to not use LoadWait, and calling it manually, but the results are the same.2nd:The file is delivered perfect to the individual, so long as a Captcha isn't displayed on the site. Now, as you can see from the source code below, I have added a new function to take a screen-shot of the Captcha using the ScreenCapture UDF, and sends it to the individual using MSN, that individual returns the Captcha answer, and it's supposed to proceed with the GiveTorrent() function. Instead, when it hits line 193;$Torrent = _FileListToArray(@UserProfileDir & "\Downloads","*.torrent",1)@Error is triggered, for the file not being found. I don't understand why this ONLY happens if the user has to return the Captcha, at no point is the file deleted... and it wouldn't have made it that far otherwise, as I have Error checking all over the place.Thanks guys.expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Compression=4 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <File.au3> #include <String.au3> #include <FTP.au3> #include <IE.au3> #Include <ScreenCapture.au3> #RequireAdmin Opt("TrayIconDebug", 1) $oMessenger = ObjCreate("Messenger.UIAutomation.1") $server = '*****' $username = '*****' $pass = '*****' ;;;; Declared Vars ;;;; Global $ClipBoard Global $Email Global $Request Global $Hand Global $IE Global $oLinks Global $sLinkText Global $CaptchaCheck Global $IE_Control Global $Wait = 1 Global $Torrent Global $Timer Global $List Global $ContactPos Global $User Global $Trigger Global $Match Global $ControlPos Global $CaptchaAnswer Global $CaptchaForm Global $CaptchaField Global $CaptchaSubmit Global $DemonoidUser Global $DemonoidPass Global $LoginURL Global $LoginObj Global $LoginForm Global $DemonoidUserField Global $DemonoidPassField Global $LoginSubmit Global $Return ;;; End Declared Globals ;;;; Opt("MustDeclareVars",1) ;;;; Demonoid Login ;;;; $DemonoidUser = "*****" $DemonoidPass = "*****" $LoginURL = "http://www.demonoid.com/account_handler.php" $LoginObj = _IECREATE($LoginURL, 0, 1) $LoginForm = _IEFORMGETCOLLECTION($LoginObj, 0) $DemonoidUserField = _IEFORMELEMENTGETOBJBYNAME($LoginForm, "nickname") $DemonoidPassField = _IEFORMELEMENTGETOBJBYNAME($LoginForm, "password") $LoginSubmit = _IEGETOBJBYNAME($LoginObj, "Submit") _IEFORMELEMENTSETVALUE($DemonoidUserField, $DemonoidUser) _IEFORMELEMENTSETVALUE($DemonoidPassField, $DemonoidPass) _IEACTION($LoginSubmit, "click") Sleep(5000) _IEQuit($LoginObj) ;;;; Demonoid Login ;;;; ;;;; Make sure *.Torrents are cleaned out first ;;;; FileDelete(@UserProfileDir & "\Downloads\*.torrent") ;;;;-------------------DONE---------------------;;;; While 1 InetGet("http://www.binarybrother.com/MSNReq/guestbook.dat", @ScriptDir & "\Requests.txt", 1) _FileReadToArray(@ScriptDir & "\Requests.txt", $List) If Not @error Then For $N = 1 To $List[0] If StringInStr($List[$N], "Pending") Then $Email = StringRegExp($List[$N], "([^\s]+@[^\s]+\.[^\s]{3})", 3) $Request = _StringBetween($List[$N], "<", ">") If Not IsArray($Email) Or Not IsArray($Request) Then $List[$N] = StringReplace($List[$N], "Pending", "Rejected") _FileWriteToLine(@ScriptDir & "\Requests.txt", $N, $List[$N], 1) UpdateReqFile() Else AddContact() $oMessenger.InstantMessage($Email[0]) WinWait("[CLASS:IMWindowClass]") $User = WinGetTitle("[CLASS:IMWindowClass]") Send('You requested "' & _StringProper($Request[0]) & '". I will process your request ASAP.{ENTER}') Send("!{F4}") GetTorrent() GiveTorrent() UpdateReqFile() EndIf EndIf Next EndIf Sleep(5000) WEnd Func UpdateReqFile() $Hand = _FTPOpen('AutoFTP') ;_FTPConnect($Hand, $server, $username, $pass, 0, 1) _FTPConnect($Hand, $server, $username, $pass, 0, 1,0x08000000) If @error Then TrayTip("Error", "Connection Failed/Check Firewall", 5) Else TrayTip("Connected", "Connection via FTP was successful.", 5) EndIf ;_FtpPutFile($Hand, @ScriptDir & "\Requests.txt", '/public_html/MSNReq/guestbook.dat') _FtpPutFile($Hand, @ScriptDir & "\Requests.txt", '/public_html/MSNReq/guestbook.dat', 0x08000000) If @error Then TrayTip("Error", "Upload Failed/Check Firewall", 5) Else TrayTip("Uploaded", "The update has been uploaded.", 5) EndIf _FTPClose($Hand) EndFunc ;==>UpdateReqFile Func GetTorrent() While 1 $IE = _IECreate("http://www.demonoid.com/files/?category=0&subcategory=All&quality=All&seeded=0&external=2&query=" & $Request[0] & "&uid=0&sort=C", 0, 1) ;_IELoadWait($IE) WinActivate("Demonoid.com") $Trigger = _IEBodyReadText($IE) If StringRegExp($Trigger, "No torrents found") = True Then $oMessenger.InstantMessage($Email[0]) WinWait($User) Send("Sorry, your search returned no results...{ENTER}") $List[$N] = StringReplace($List[$N], "Pending", "No-Results") _FileWriteToLine(@ScriptDir & "\Requests.txt", $N, $List[$N], 1) ExitLoop EndIf If StringRegExp($Trigger,"We will be back as soon as possible") = True Then $oMessenger.InstantMessage($Email[0]) WinWait("[CLASS:IMWindowClass]") Send("Demonoid seems to be offline... Sorry.{ENTER}") $List[$N] = StringReplace($List[$N], "Pending", "Source-Down") _FileWriteToLine(@ScriptDir & "\Requests.txt", $N, $List[$N], 1) ExitLoop EndIf WinActivate("Demonoid.com") $oLinks = _IELinkGetCollection($IE) For $oLink In $oLinks $sLinkText = _IEPropertyGet($oLink, "innerText") If StringInStr($sLinkText, $Request[0]) Then _IEAction($oLink, "click") ExitLoop EndIf Next WinActivate("Demonoid.com") _IELoadWait($IE) WinActivate("Demonoid.com") $oLinks = _IELinkGetCollection($IE) For $oLink In $oLinks $sLinkText = _IEPropertyGet($oLink, "innerText") If StringInStr($sLinkText, "Click here to download the torrent") Then _IEAction($oLink, "click") ExitLoop EndIf Next WinActivate("Demonoid.com") _IELoadWait($IE) $CaptchaCheck = _IEBodyReadText($IE) If StringRegExp($CaptchaCheck,"Please type the validation code") = True Then $Return = CaptchaSystem() If $Return = 0 Then ExitLoop EndIf WinWait("File Download", "Do you want to",10) ControlClick("File Download", "Do you want to", 4427) $Wait = WinWait("Save As","",5) If $Wait = 0 Then ControlClick("File Download", "Do you want to", 4427) EndIf WinWait("Save As","",5) ;ControlSetText("Save As", "", 1001, @ScriptDir & "\" & $Request[0]) Send("{ENTER}") While WinExists("File Download") Sleep(500) WEnd _IEQuit($IE) ExitLoop WEnd EndFunc Func GiveTorrent() While 1 $oMessenger.InstantMessage($Email[0]) WinWait("[CLASS:IMWindowClass]") $Torrent = _FileListToArray(@UserProfileDir & "\Downloads","*.torrent",1) If @Error Then Send("Hmm... Something went wrong, and I never downloaded the torrent file, although it was found... Try again later.{ENTER}") Send("!{F4}") $List[$N] = StringReplace($List[$N], "Pending", "Torrent-Fail") _FileWriteToLine(@ScriptDir & "\Requests.txt", $N, $List[$N], 1) ExitLoop EndIf Send("Alright, I found it... Here it comes...{ENTER}") Send("!af") While Not WinExists("Send a File") ControlSetText("Send a File to", "", 1148, @UserProfileDir & "\Downloads\" & $Torrent[1]) Sleep(1000) $Wait +=1 If $Wait = 6 Then Send("You were not online, appearing offline, or did not have me added... Sorry, file sending failed...{ENTER}") $List[$N] = StringReplace($List[$N], "Pending", "Torrent-Receive-Failed") _FileWriteToLine(@ScriptDir & "\Requests.txt", $N, $List[$N], 1) ExitLoop(2) EndIf ControlSetText("Send a File to", "", 1148, @UserProfileDir & "\Downloads\" & $Torrent[1]) WEnd ControlSetText("Send a File to", "", 1148, @UserProfileDir & "\Downloads\" & $Torrent[1]) Send("{ENTER}") $Timer = TimerInit() While 1 FileWriteLine() Sleep(5000) Send("!{F4}") Sleep(1500) If WinExists("Windows Live Messenger","Closing this window will end all current activities with this contact.") Then Send("n") Else FileDelete(@UserProfileDir & "\Downloads\*.torrent") $List[$N] = StringReplace($List[$N], "Pending", "Completed") _FileWriteToLine(@ScriptDir & "\Requests.txt", $N, $List[$N], 1) ExitLoop(2) EndIf If TimerDiff($Timer) > 120000 Then Send('You had 2 minutes to accept the file, you failed to do so, or waited too long, connection terminated. The Status of your request has been set to "Torrent-Receive-Failed".{ENTER}') FileDelete(@UserProfileDir & "\Downloads\*.torrent") $List[$N] = StringReplace($List[$N], "Pending", "Torrent-Receive-Failed") _FileWriteToLine(@ScriptDir & "\Requests.txt", $N, $List[$N], 1) ExitLoop(2) EndIf WEnd WEnd EndFunc ;==>GetGiveTorrent Func AddContact() $oMessenger.AddContact(0, $Email[0]) WinWaitActive("[CLASS:UXContacts_Add_Dialog]") $ContactPos = WinGetPos("[CLASS:UXContacts_Add_Dialog]") Send("{ENTER}") Sleep(1000) PixelSearch($ContactPos[0], $ContactPos[1], $ContactPos[2], $ContactPos[3], 0xFFFFC5, 5) If Not @error Then Send("{TAB 5}{SPACE}") Else ClipPut("You made a request on http://www.BinaryBrother.com, this is the Bot for that request.") ControlClick("Windows Live Messenger", "", "[CLASS:DirectUIHWND; INSTANCE:1]") Send("^v{TAB 2}{SPACE}") While 1 PixelSearch($ContactPos[0], $ContactPos[1], $ContactPos[2], $ContactPos[3], 0x355A88, 5) If Not @error Then ExitLoop Sleep(1000) WEnd Send("{TAB}{SPACE}") EndIf EndFunc ;==>AddContact Func CaptchaSystem() $IE_Control = ControlGetHandle("Demonoid.com","","[CLASS:Internet Explorer_Server]") WinSetState("Demonoid.com","",@SW_MAXIMIZE) _ScreenCapture_CaptureWnd(@UserProfileDir & "\Downloads\Captcha.jpg",$IE_Control,26,268,82,289) $oMessenger.InstantMessage($Email[0]) Send("Demonoid hit me with a Captcha, your going to have to tell me what it is.{ENTER}") Send("Here is the Captcha, no need to actually accept the file, you should be able to see ") Send('it clearly, you have 2 minutes to tell me what the Captcha is, or your Torrent request will be classified as "Captcha-Fail".{ENTER}') Send("!af") $Wait = WinWait("Send a File to", "", 20) If $Wait = 0 Then Send("You were not online, appearing offline, or did not have me added... Sorry, you failed to acquire the Captcha, try again later.{ENTER}") Send('Your status for this request has been set to "Captcha-TimeOut".{ENTER}') $List[$N] = StringReplace($List[$N], "Pending", "Captcha-TimeOut") _FileWriteToLine(@ScriptDir & "\Requests.txt", $N, $List[$N], 1) Return $Wait EndIf While WinExists("Send a File to") ControlSetText("Send a File to", "", 1148, @UserProfileDir & "\Downloads\Captcha.jpg") ControlSetText("Send a File to", "", 1148, @UserProfileDir & "\Downloads\Captcha.jpg") ControlSetText("Send a File to", "", 1148, @UserProfileDir & "\Downloads\Captcha.jpg") Send("{ENTER}") WEnd Send('This bot requires you to include the Captcha numbers inside @ Tags, like so... "Hey Mr.Bot, the Captcha is @12332@...", or just @12332@ will work fine...{ENTER}') Send("!{F4}") Send("y") $Timer = TimerInit() WinWaitClose($User) While Not WinExists($User) Sleep(500) If TimerDiff($Timer) > 120000 Then $oMessenger.InstantMessage($Email[0]) Send('You did not reply with the Captcha answer within 2 minutes, your request has been marked as "Captcha-Return-Failed".{ENTER}') $List[$N] = StringReplace($List[$N], "Pending", "Captcha-Return-Failed") _FileWriteToLine(@ScriptDir & "\Requests.txt", $N, $List[$N], 1) ExitLoop EndIf WEnd While Not WinActive($User) WinActivate($User) WEnd WinSetState($Match,"",@SW_MAXIMIZE) Sleep(1000) MouseClick("primary",@DesktopWidth/2,@DesktopHeight/2,2) Send("^a") Send("^c") Send("^c") $ClipBoard = ClipGet() $CaptchaAnswer = _StringBetween($ClipBoard,"@","@",-1,1) ;MsgBox(0,"",$CaptchaAnswer[0]) If Not StringIsDigit($CaptchaAnswer[0]) Or Not IsArray($CaptchaAnswer) Then Send('Sorry, you gave an answer that did not contain numeric characters only, or was not inclosed in the proper tags, your request has been set to "Captcha-Return-Incorrect"{ENTER}') Send("If this was was not intentional, you will need to re-submit your request, sorry...{ENTER}") Send("!{F4}") $List[$N] = StringReplace($List[$N], "Pending", "Captcha-Return-Incorrect") _FileWriteToLine(@ScriptDir & "\Requests.txt", $N, $List[$N], 1) Else WinActivate("Demonoid.com") $CaptchaForm = _IEFORMGETCOLLECTION($IE, 0) $CaptchaField = _IEFORMELEMENTGETOBJBYNAME($CaptchaForm, "validation") _IEFORMELEMENTSETVALUE($CaptchaField, $CaptchaAnswer[0]) ;$CaptchaSubmit = _IEGETOBJBYNAME($IE, "Submit") ;_IEACTION($CaptchaSubmit, "click") _IEFormSubmit($CaptchaForm) EndIf EndFunc Edited April 6, 2009 by BinaryBrother SIGNATURE_0X800007D NOT FOUND Link to comment Share on other sites More sharing options...
DaleHohm Posted March 26, 2009 Share Posted March 26, 2009 For your 1st question. Technically, IE.au3 does not "hang" in _IELoadWait, but rather it "loops" waiting for the page complete conditions. The length of time it loops is controlled with _IELoadWaitTimeout() and defaults to 5 minutes. I ran the following code and had no trouble: #include <IE.au3> $LoginURL = "http://www.demonoid.com/account_handler.php" $LoginObj = _IECREATE($LoginURL, 0, 1) does this give you trouble? Didn't study your second question. Dale Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble Link to comment Share on other sites More sharing options...
BinaryBrother Posted March 26, 2009 Author Share Posted March 26, 2009 I had no problem with that code, the code I was having a problem with was on line 157+. I'll post the bit below as to make it more clear, and I bolded that information on my first post. Sorry I wasn't clear enough. While 1 $IE = _IECreate("http://www.demonoid.com/files/?category=0&subcategory=All&quality=All&seeded=0&external=2&query=" & $Request[0] & "&uid=0&sort=C", 0, 1) ;_IELoadWait($IE) WinActivate("Demonoid.com") $Trigger = _IEBodyReadText($IE) If StringRegExp($Trigger, "No torrents found") = True Then $oMessenger.InstantMessage($Email[0]) WinWait($User) Send("Sorry, your search returned no results...{ENTER}") $List[$N] = StringReplace($List[$N], "Pending", "No-Results") _FileWriteToLine(@ScriptDir & "\Requests.txt", $N, $List[$N], 1) ExitLoop EndIf If StringRegExp($Trigger,"We will be back as soon as possible") = True Then $oMessenger.InstantMessage($Email[0]) WinWait("[CLASS:IMWindowClass]") Send("Demonoid seems to be offline... Sorry.{ENTER}") $List[$N] = StringReplace($List[$N], "Pending", "Source-Down") _FileWriteToLine(@ScriptDir & "\Requests.txt", $N, $List[$N], 1) ExitLoop EndIf WinActivate("Demonoid.com") $oLinks = _IELinkGetCollection($IE) For $oLink In $oLinks $sLinkText = _IEPropertyGet($oLink, "innerText") If StringInStr($sLinkText, $Request[0]) Then _IEAction($oLink, "click") ExitLoop EndIf Next WinActivate("Demonoid.com") _IELoadWait($IE) SIGNATURE_0X800007D NOT FOUND Link to comment Share on other sites More sharing options...
DaleHohm Posted March 26, 2009 Share Posted March 26, 2009 So I cannot run that code to reproduce. My guess is that the page looks to be loaded, but is actually does not finish. One suggestion would be to disable the wait and then use _IEPropertyGet($oIE, "readystate") and wait for it to get to 3, which is when it is not totally complete, but can be interacted with. Dale Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble Link to comment Share on other sites More sharing options...
BinaryBrother Posted March 27, 2009 Author Share Posted March 27, 2009 Uh oh... This is weird... C:\Program Files\AutoIt3\Include\IE.au3 (2241) : ==> Variable must be of type "Object".: Return $o_object.document.body.innerText Return $o_object.document.body^ ERROR This is what I used... Func GetTorrent() While 1 $IE = _IECreate("http://www.demonoid.com/files/?category=0&subcategory=All&quality=All&seeded=0&external=2&query=" & $Request[0] & "&uid=0&sort=C", 0, 1,0) While Not _IEPropertyGet($IE, "readystate") = 3 Sleep(500) WEnd WinActivate("Demonoid.com") Line 123 - 129 was changed in my initial post. To the above code. SIGNATURE_0X800007D NOT FOUND Link to comment Share on other sites More sharing options...
DaleHohm Posted March 27, 2009 Share Posted March 27, 2009 There s nothing in the code you posted that uses .innerhtml Your disgnosis of the problem is incomplete. Also, suggest you use <= 4 instead of 3 Also guard against doing _IECreate in a tight loop Dale Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble Link to comment Share on other sites More sharing options...
BinaryBrother Posted March 27, 2009 Author Share Posted March 27, 2009 The _IECreate() is in a one way loop that doesn't execute more than once during that session, I just use it as a container to allow If statements to exit early. Which should actually be "Return" instead... but anyway... I managed to workout the IE issue, does anyone have any ideas why @Error is being set in the above specified place, for that FileRead Array? SIGNATURE_0X800007D NOT FOUND Link to comment Share on other sites More sharing options...
Skruge Posted March 27, 2009 Share Posted March 27, 2009 I managed to workout the IE issue, does anyone have any ideas why @Error is being set in the above specified place, for that FileRead Array?During a download, IE builds the file in its cache before moving it to its final destination.Does the file exist at any point after your script fails to find it?If so, you need a slight delay before checking for files. (or loop and check a few times)If not, _IEQuit($IE) may be interrupting the file move, so wait for the file before quitting. [font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font] Link to comment Share on other sites More sharing options...
BinaryBrother Posted April 6, 2009 Author Share Posted April 6, 2009 Sorry it took me so long to reply, but Skruge's suggestion was right, before the file could get transferred from the temp location to the ScriptDir, I was killing IE... What are the odds of that? haha.Thanks Dale.Thanks Skruge.You are both excellent sources of knowledge. SIGNATURE_0X800007D NOT FOUND Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now