mikehunt114 Posted August 1, 2007 Share Posted August 1, 2007 (edited) #include <IE.au3> $url = "www.newzbin.com" $oIE = _IECreate($url, 1) $oForm = _IEFormGetCollection($oIE, 0) $oQuery = _IEFormElementGetObjByName($oForm, "q") $oCategory = _IEFormElementGetObjByName($oForm, "Category") $oFP = _IEFormElementGetObjByName($oForm, "searchFP") _IEFormElementSetValue($oQuery, "search") _IEFormElementOptionselect($oCategory, "TV::Other", 1, "byText") _IEFormElementOptionselect($oFP, "Files", 1, "byText") _IEFormSubmit($oForm) Edited August 1, 2007 by mikehunt114 IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font] Link to comment Share on other sites More sharing options...
dufran3 Posted August 1, 2007 Author Share Posted August 1, 2007 that worked well. I was wanting to add 1 check that I am not sure how to do. Say, you do a search for "asdf" in "TV::All". It returns nothing and you get a message that says: "No results could be found" The HTML for that is here: <div id="Content"> <p class="Message"> <span class="Err">No results could be found</span> </p> </div> I was looking through the IE.au3 file, and found a couple of things that I thought would work, but I'm not sure how to use them...here are the functions I was looking at.. _IEDocReadHTML() _IEBodyReadText() _IEBodyReadHTML() I was thinking I would do a simple If EndIf Statement that checks to see if the text "No results could be found" was there...is this possible? Link to comment Share on other sites More sharing options...
AzKay Posted August 1, 2007 Share Posted August 1, 2007 If StringInStr(_IEBodyReadHtml($oIE), "No results could be found") Then MsgBox(0, "", "Nothing found.") # MY LOVE FOR YOU... IS LIKE A TRUCK- # Link to comment Share on other sites More sharing options...
mikehunt114 Posted August 1, 2007 Share Posted August 1, 2007 Sure, something like this maybe: $sText = _IEBodyReadText($oIE) If StringInStr($sText, "No results could be found") Then MsgBox(0, "Result", "No results found.")oÝ÷ Øêâ*.j·°¢ºâyÖ¢ëmÂݱ·¢èºw^Ç°êÞ{az zf²mèÂ¥u·¦¢·©®ç^Ûh$¢yr{ay*Zljëh×6$oSpans = _IETagNameGetCollection($oIE, "SPAN") For $oSpan In $oSpans $sText = $oSpan.innerText If StringInStr($sText, "No results could be found") Then MsgBox(0, "Result", "No results found.") Next Cheers. IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font] Link to comment Share on other sites More sharing options...
dufran3 Posted August 1, 2007 Author Share Posted August 1, 2007 Sure, something like this maybe: CODE: AutoIt $sText = _IEBodyReadText($oIE) If StringInStr($sText, "No results could be found") Then MsgBox(0, "Result", "No results found.") Or if you are worried about those words being found elsewhere in the page, maybe it would be more prudent to look only in the Span's: CODE: AutoIt $oSpans = _IETagNameGetCollection($oIE, "SPAN") For $oSpan In $oSpans $sText = $oSpan.innerText If StringInStr($sText, "No results could be found") Then MsgBox(0, "Result", "No results found.") Next Cheers. Dude, you have been really helpful. I am so lost on how these collections work. Maybe you could explain them to me again...because I am going to be using them a lot it looks like. Now, after I did all that. I am going to be looking for the results...which are links.... I think I'm going to have to use _IELinkGetCollection, however. I'm still unsure of how to use it. $oLinkCollect = _IELinkGetCollection($oIE) I was trying to use what you gave me as an example....but I can't figure out where the $oSpan variable is being assigned... and what $oSpan.innerText is doing....I'm really sorry man...but you are being such good help!!! Thanks Again! Link to comment Share on other sites More sharing options...
AzKay Posted August 2, 2007 Share Posted August 2, 2007 Completely ignored, Hoooooo!~ # MY LOVE FOR YOU... IS LIKE A TRUCK- # Link to comment Share on other sites More sharing options...
AzKay Posted August 2, 2007 Share Posted August 2, 2007 ; ******************************************************* ; Example 1 - Open browser with basic example, get link collection, ; loop through items and display the associated link URL references ; ******************************************************* ; #include <IE.au3> $oIE = _IE_Example ("basic") $oLinks = _IELinkGetCollection ($oIE) $iNumLinks = @extended MsgBox(0, "Link Info", $iNumLinks & " links found") For $oLink In $oLinks MsgBox(0, "Link Info", $oLink.href) Next # MY LOVE FOR YOU... IS LIKE A TRUCK- # Link to comment Share on other sites More sharing options...
GMK Posted August 2, 2007 Share Posted August 2, 2007 (edited) I can't figure out where the $oSpan variable is being assigned... and what $oSpan.innerText is doing....In mikehunt114's script:$oSpan is the variable assigned for the loop.$oSpans = a collection of SPAN tags$oSpan = each individual SPAN tag called in the For loop$oSpan.innerText = the text you are searching through (see MSDN)And as AzKay seems to be suggesting, the help file is your friend. Edited August 2, 2007 by GMK Link to comment Share on other sites More sharing options...
mikehunt114 Posted August 2, 2007 Share Posted August 2, 2007 Completely ignored, Hoooooo!~Sucka. Dude, you have been really helpful. I am so lost on how these collections work. Maybe you could explain them to me again...because I am going to be using them a lot it looks like. Now, after I did all that. I am going to be looking for the results...which are links.... I think I'm going to have to use _IELinkGetCollection, however. I'm still unsure of how to use it. $oLinkCollect = _IELinkGetCollection($oIE) I was trying to use what you gave me as an example....but I can't figure out where the $oSpan variable is being assigned... and what $oSpan.innerText is doing....I'm really sorry man...but you are being such good help!!! Thanks Again!To epxand on GMK's answer: Collections are similar in theory to arrays: they hold a multitude of elements in a single variable. They are different though, and this becomes apparent when you need to enumerate and loop through the collection. The way I used "For $oSpan In $oSpans" is a method of enumerating the collection of SPAN objects. It's similar to looping through arrays. The name of the variable $oSpan is arbitrary, it just points to the multiple single objects inside the collection. I use that notation because it's easy for me to understand. What I did with the $oSpan.innerText is just retrieve the text of the object. ".innerText" is a COM call for a low level DOM property. The same thing can be done using _IEPropertyGet($object, "innerText"). For something like this in HTML: <SPAN>Some sort of text here.</SPAN> It would return "Some sort of text here.". The innerText property is available for almost every element in a document. There are many different types of properties like this, AzKay showed another in the example from the helpfile (.href). They are all documented at MSDN, but Dale has included the most commonly used ones in his _IEPropertyGet function. Hopefully that was a decent explanation. IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font] Link to comment Share on other sites More sharing options...
dufran3 Posted August 2, 2007 Author Share Posted August 2, 2007 Thanks mikehunt114, that was a really good explanation, helped me wrap my head around that a little bit. Also AzKay, thanks for the snippet. Where did you find that at? Could someone maybe provide a link to some good IE.au3 examples and stuff. Thanks A lot! Link to comment Share on other sites More sharing options...
mikehunt114 Posted August 2, 2007 Share Posted August 2, 2007 AzKay's example was from the helpfile, under _IELinkGetCollection....surprise surprise. IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font] Link to comment Share on other sites More sharing options...
dufran3 Posted August 2, 2007 Author Share Posted August 2, 2007 ok, i'm learning a bunch about IE.au3 from reading the help...and of course from you. I have been able to interact with the login form...by using some snippet that you gave me and modified it. When I look at the source for the login button, it doesn't appear to have a name...or ID. How do I "submit" it without a name....below is the code I have so far.... $oFormLogin = _IEFormGetCollection($oIE, 3) $oQueryLogin = _IEFormElementGetObjByName($oFormLogin, 'username') $oQueryPass = _IEFormElementGetObjByName($oFormLogin,'password') $oSubmitLogin = _IEFormElementGetObjByName($oFormLogin,'submit') ;<=--- Can't figure out how to use since "submit" isn't the name...it doesn't have one! _IEFormElementSetValue($oQueryLogin, 'username') ;<--- Works _IEFormElementSetValue($oQueryPass,'password') ;<--- Works _IEFormSubmit($oSubmitLogin) ;<--- Not workingoÝ÷ Ø l ¦¶¼¢hr·µë(ë(®ÚrØZ·¥ÇÂêںǫÉhz+S®'¶¬zØb²Éâ¦" -~º&ʺҢ}ý¶ØbHÂ)eÂämçºÇꮢÒè)êºm{]¡ë'ßÛlyé¡·¢ª®¢Û)jz®¢ÛZ«¢+ØÀÌØí½MÁ¹Ìô}%Q9µÑ ½±±Ñ¥½¸ ÀÌØí½%°ÅÕ½ÐíMA8ÅÕ½Ðì¤)½ÈÀÌØí½MÁ¸%¸ÀÌØí½MÁ¹Ì(ÀÌØíÍQáÐôÀÌØí½MÁ¸¹¥¹¹ÉQáÐ(%MÑÉ¥¹%¹MÑÈ ÀÌØíÍQáаÅÕ½Ðí1½¥¸ÅÕ½Ðì¤Q¡¸5Í ½à À°ÅÕ½ÐíIÍÕ±ÐÅÕ½Ðì°ÅÕ½Ðí9½Ð±½¥¸¸ÅÕ½Ðì¤)9á Thanks again...trudging on... Link to comment Share on other sites More sharing options...
dufran3 Posted August 2, 2007 Author Share Posted August 2, 2007 ok, i'm learning a bunch about IE.au3 from reading the help...and of course from you. I have been able to interact with the login form...by using some snippet that you gave me and modified it. When I look at the source for the login button, it doesn't appear to have a name...or ID. How do I "submit" it without a name....below is the code I have so far.... $oFormLogin = _IEFormGetCollection($oIE, 3) $oQueryLogin = _IEFormElementGetObjByName($oFormLogin, 'username') $oQueryPass = _IEFormElementGetObjByName($oFormLogin,'password') $oSubmitLogin = _IEFormElementGetObjByName($oFormLogin,'submit') ;<=--- Can't figure out how to use since "submit" isn't the name...it doesn't have one! _IEFormElementSetValue($oQueryLogin, 'username') ;<--- Works _IEFormElementSetValue($oQueryPass,'password') ;<--- Works _IEFormSubmit($oFormLogin) ;<--- Working now Thanks again...trudging on... CHANGE : I was able to submit the form without needing a name. Just using the "$oFormLogin" handle. any ideas on checking if I am already logged in or not? Link to comment Share on other sites More sharing options...
mikehunt114 Posted August 2, 2007 Share Posted August 2, 2007 (edited) You did the right thing to submit the form, you want to use the form object handle in _IEFormSubmit, not try to get a form element named "submit". Another way to submit a form is to _IEAction("click") on the button itself.As for checking if the user is logged in, you'll have to look for something in the HTML source. If there is a text somewhere that says "logged in" or something like that, determine it's location and then check for it in your script. If you need help deciphering the HTML, post it in a codebox or attachment, or post the URL and we'll take a look at it.Edit: typo Edited August 2, 2007 by mikehunt114 IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font] Link to comment Share on other sites More sharing options...
dufran3 Posted August 2, 2007 Author Share Posted August 2, 2007 It is at www.newzbin.com, when you are not logged in, on the left hand column, there is a "login" text and the forms. when logged in, it isn't there. Here is what I think is the relevant code. <div class="section"> <h3>Login</h3> <form method="post" action="/account/login/"> <div class="subsection"> <label for="username">Username:</label> <input id="username" type="text" name="username" size="12" /> <label for="password">Password:</label> <input id="password" type="password" name="password" size="12" /> <br /> <a href="/account/lost/#lostpass">Lost password?</a> <br /> <input type="submit" onclick="return checkSystemTime();" Link to comment Share on other sites More sharing options...
mikehunt114 Posted August 2, 2007 Share Posted August 2, 2007 You can do pretty much the same thing I showed you earlier, but just use the Header elements instead. H1 through H6 stand for different styles of headers. #include <IE.au3> $url = "www.newzbin.com" $oIE = _IECreate($url, 1) $oHeaders = _IETagNameGetCollection($oIE, "H3") For $oHeader In $oHeaders $sText = $oHeader.innerText If StringInStr($sText, "Login") Then MsgBox(0, "", "Not logged in.") ExitLoop EndIf Next IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font] Link to comment Share on other sites More sharing options...
dufran3 Posted August 2, 2007 Author Share Posted August 2, 2007 looks like my HTML skills are very very lacking! Thanks, that helped. It seems like I figure out how to do something, then try to reuse that same method, and it doesn't work...like...clicking a button...lol...Trying to click the "Get Message ID's button" and it doesn't work. Here is my script so far. You should be able to run it so you can see what I am trying to get at here. expandcollapse popup;Newzbin Downloader #include <GuiConstants.au3> #include <IE.au3> _NewzBinGUI() _NewzBinWeb() Func _NewzBinGUI() ;Create GUI $Main = GUICreate('Newzbin Auto Downloader', 300, 100) Opt("GUICoordMode",1) $CollectName = GUICtrlCreateInput('',100,10,150) $NameLabel = GUICtrlCreateLabel('Name of Item',20,13) $CollectCategory = GUICtrlCreateCombo('',100,35,60,$CBS_UPPERCASE,$CBS_DROPDOWNLIST) GUICtrlSetData(-1,"Unknown|Anime|Apps|Books|Consoles|Emulation|Games|Misc|Movies|Music|PDA|TV") $CategoryLabel = GUICtrlCreateLabel('Category',20,38) $CollectMaxItems = GUICtrlCreateInput('',100,60,50) $MaxItemsLabel = GUICtrlCreateLabel('Max # of Items',20,63) $Button_1 = GUICtrlCreateButton ("OK", 200, 65, 40, 0, 0x0001) $Button_2 = GUICtrlCreateButton ("Exit", 245, 65, 40, 0) $GUIIcon = GUISetIcon(@ScriptDir & '\newzbin.ico') GUISetState () ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() Select Case $msg = -3 Exit Case $msg = $Button_1 GLOBAL $Name = GUICtrlRead($CollectName) GLOBAL $Category = GUICtrlRead($CollectCategory) GLOBAL $MaxItems = GUICtrlRead($CollectMaxItems) If $Name == '' OR $Category =='' Then MsgBox(0,'Name','Both name and category are required!') Else WinSetState('Newzbin Auto Downloader','',@SW_HIDE) ExitLoop EndIf Case $msg = $Button_2 Exit EndSelect Wend EndFunc Func _NewzBinWeb() $url = "www.newzbin.com" $oIE = _IECreate($url, 1) ;Check to see if logged In $oHeaders = _IETagNameGetCollection($oIE, "H3") For $oHeader In $oHeaders $sText = $oHeader.innerText If StringInStr($sText, "Login") Then ;Login $oFormLogin = _IEFormGetCollection($oIE, 3) $oQueryLogin = _IEFormElementGetObjByName($oFormLogin, 'username') $oQueryPass = _IEFormElementGetObjByName($oFormLogin, 'password') $oSubmitLogin = _IEFormElementGetObjByName($oFormLogin, 'submit') _IEFormElementSetValue($oQueryLogin, 'username') _IEFormElementSetValue($oQueryPass, 'password') _IEFormSubmit($oFormLogin) ExitLoop EndIf Next $oForm = _IEFormGetCollection($oIE, 0) $oQuery = _IEFormElementGetObjByName($oForm, "q") $oCategory = _IEFormElementGetObjByName($oForm, "Category") $oFP = _IEFormElementGetObjByName($oForm, "searchFP") ;Setting Search title and category _IEFormElementSetValue($oQuery, $Name) _IEFormElementOptionselect($oCategory, $Category & '::All', 1, "byText") _IEFormSubmit($oForm) ;Check if search returned nothing $oSpans = _IETagNameGetCollection($oIE, "SPAN") For $oSpan In $oSpans $sText = $oSpan.innerText If StringInStr($sText, "No results could be found") Or StringInStr($sText, 'Sorry. There were no results to display for your query.') Then MsgBox(0, "Result", "No results found. Exiting script and closing IE!") _IEQuit($oIE) Exit EndIf Next ;Check for items found $oLinks = _IELinkGetCollection($oIE) $iNumLinks = @extended Dim $aPosts[600] $i = 0 For $oLink In $oLinks If StringInStr($oLink.href, 'browse/post') Then If Not StringInStr($oLink.href, '#') Then $aPosts[$i] = $oLink.href $i += 1 EndIf EndIf Next $aPostsSize = $i - 1 For $i = 0 to $aPostsSize _IENavigate($oIE, $aPosts[$i]) ;Get message ID's $oFormIDS = _IEFormGetCollection($oIE, 1) $oQuery = _IEFormElementGetObjByName($oFormIDS, "msgidlist") _IEFormSubmit($oFormIDS) ;_IEAction($oFormIDS,'click') Exit Next EndFunc Func IsVisible($handle) If BitAnd( WinGetState($handle), 2 ) Then Return 1 Else Return 0 EndIf EndFunc Link to comment Share on other sites More sharing options...
mikehunt114 Posted August 2, 2007 Share Posted August 2, 2007 You'll have to post some HTML source. IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font] Link to comment Share on other sites More sharing options...
dufran3 Posted August 2, 2007 Author Share Posted August 2, 2007 only 1 line looks relevant to my noobish eyes, however I took some before and after just incase. <table summary="Attached Files" class="postview"> <tr> <th> Attached Files </th> <th colspan="2"> <input type="submit" name="msgidlist" value="Get Message-IDs" /> [<input type="checkbox" name="dupes" /> include dupes] Link to comment Share on other sites More sharing options...
mikehunt114 Posted August 2, 2007 Share Posted August 2, 2007 Have you tried: $oButton = _IEGetObjByName($oIE, "msgidlist") IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font] 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