vrap Posted February 19, 2009 Share Posted February 19, 2009 Basic run down is that i want to check a page for some text, if it is there, to click the last link found on the page, this is what i have so far, but it doesnt seem to work: #include <IE.au3> $waiting = 0 $oIE = _IECreate("http://somelink.net") while $waiting = 0 $sText = _IEBodyReadText ($oIE) $iNumLinks = @extended $last_link = _IELinkGetCollection($oIE, $iNumLinks - 6); get the 6th last link .. $result = StringInStr($sText, "beautiful") ; check for the text beautiful if not $result = 0 then _IEAction($last_link, "click") $waiting = 1 EndIf Sleep(1200) _IENavigate ($oIE, "http://somelink.net") ; refresh? wend any ideas, i cant seem to find any info on checking a page for text :S Link to comment Share on other sites More sharing options...
Authenticity Posted February 19, 2009 Share Posted February 19, 2009 Is the beautiful string is part of the inner or outer link string? Does it supposed to appear only once in the entire body source? Link to comment Share on other sites More sharing options...
vrap Posted February 19, 2009 Author Share Posted February 19, 2009 (edited) yes its only supposed to appear once. and it only will if its there. EDIT: in fact, if i could isolate the text at a certain point in the page it would be even better. Edited February 19, 2009 by vrap Link to comment Share on other sites More sharing options...
Authenticity Posted February 19, 2009 Share Posted February 19, 2009 Try this few notes: -First don't navigate again to the same site, instead, use _IEAction($oIE, 'refresh') and _IELoadWait($oIE). -Make sure that "$iNumLinks - 6" can't return negative results or you're going to get 0 as the return value or a collection if computing it results in -1. -"if not $result = 0 then" is quite confusing. Use If $result instead. The rest seems OK related to logical and syntactical code but I do think that storing the @extended macro after a call to _IEBodyReadText doesn't supposed to return any link related value. Use @extended after calling _IELinkGetCollection($oIE) Link to comment Share on other sites More sharing options...
vrap Posted February 19, 2009 Author Share Posted February 19, 2009 Perfect, thanks, i only just started coding in autoit 20 mins or so ago before i posted, just needed this personal script: heres the result if anyone is interested: #include <IE.au3> $waiting = 0 $oIE = _IECreate("http://blah.net") while $waiting = 0 $sText = _IEBodyReadText ($oIE) $oLinks = _IELinkGetCollection ($oIE, 0) $iNumLinks = @extended $last_link = _IELinkGetCollection($oIE, $iNumLinks - 1); -2 means 2nd last link and so on $result = StringInStr($sText, "enter") if $result then ;MsgBox(0, "Last link is: ", $last_link.href) _IEAction($last_link, "click") $waiting = 1 ExitLoop EndIf _IEAction($oIE, 'refresh') _IELoadWait($oIE) wend will search for beautiful and click last link. tyvm. Link to comment Share on other sites More sharing options...
vrap Posted February 19, 2009 Author Share Posted February 19, 2009 (edited) just a quick Q, is it possible to click the link as soon as the text loads, because it seems the site takes a while to fully load due to ads :S edit: AND, say its clicked on the link because it found the text, how can i check the text on the new page that has been loaded. Edited February 19, 2009 by vrap Link to comment Share on other sites More sharing options...
vrap Posted February 19, 2009 Author Share Posted February 19, 2009 Ah nvm got it, is there anyway to go back to the start of a script? Link to comment Share on other sites More sharing options...
Authenticity Posted February 19, 2009 Share Posted February 19, 2009 Yup, put everything you want before the While..WEnd loop inside a function and call it whenever you wish inside the loop. Actually going to the back of the script as it's deduced is not possible except for as mentioned above or put it all in a loop which is not wise or relaunch your program before terminating yours (must be compiled if I'm not wrong) which is the most unwise method ever. Try the first approach with the function. Link to comment Share on other sites More sharing options...
vrap Posted February 20, 2009 Author Share Posted February 20, 2009 Yeh thats what i ended up doing, just thought because it was a more user friendly language it might have one of those handy return to start of script functions, autoit is a pretty handy language ive realised, thanks for the help, my code seems to be growing quite rapidly. Link to comment Share on other sites More sharing options...
ukmazy Posted February 20, 2009 Share Posted February 20, 2009 u can use all customized loops Do, while, for ... Link to comment Share on other sites More sharing options...
vrap Posted February 20, 2009 Author Share Posted February 20, 2009 Yeh i know, im fluent in a couple of other languages, just wanted to see if it had a candy function to make things easier 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