Jump to content
Sign in to follow this  
NizonRox

Finding Text on html

Recommended Posts

NizonRox

Ive just started playing around with autoit3 for a while.. and was wondering if i can find a line of text in the html, and execute a command fx. for checking if im logged in or logged out. Im using google chrome but im willing to use IE cause for what ive learned so far is thats what you guys use mostly. Im currently looking into Chrome UDF Plzz keep me updated if you find a way to do this :)

Edited by NizonRox

Share this post


Link to post
Share on other sites
NizonRox

Error: Variable Used Without Being Declared.... Help?

#include <IE.au3>

HotKeySet ("{SPACE}", "Check")

While 1
    Sleep(100)
WEnd

Func Check ()
   MouseClick ( "LEFT", 1046, 196, 1, 1)
   Sleep(500)
If StringInStr(_IEBodyReadText($oIE), "Online") Then
      Exit
   EndIf
If StringInStr(_IEBodyReadText($oIE), "Offline") Then
      Exit
   EndIf
EndFunc

Share this post


Link to post
Share on other sites
NizonRox

If i use 

Local $oIE = _IECreate("www.autoitscript.com", 1)

And go to "www.autoitscript.com/forum
will the string find the pattern on autoitscript.com or on autoitscript.com/forum

Share this post


Link to post
Share on other sites
FlashpointBlack

It will find it in whatever URL is loaded when you hit the hotkey combination. it's basically reading whatever is in IE at any given time, you're just telling it which IE window to look at and ignoring the possibility of further automation by using things like _IENavigate()

something I just noticed though is that your source code does not do anything different if online is found or offline. not sure if that was a mistake or not...

Something like this might work better:

$HTML = _IEBodyReadText($oIE)
If StringInStr($HTML, "Online") Then
    ;Code to execute if "Online" was found in the source of currently loaded website
Elseif StringInStr($HTML, "Offline") Then
    ;Code to execute if "Offline" was found in the source of currently loaded website, and "Online" was not
Else
    ;Code to execute if neither "Online" nor "Offline" were found. (An error of some sort, perhaps wrong site loaded)
    Exit
EndIf

in this example, I put the source code for the currently loaded website into a variable so you don't have to pull it from IE more than once. the way you had it, each time you checked if a string was found, the script communicated with IE again, causing a small slowdown.

I also used "elseif" instead of two different If statements. This ensures that only one of the group will be true. In your example, if the loaded website contained both "Online" and "Offline" both sets of code would be executed.

I removed the "exit" statement from the code to run. It seems strange that you would go to the trouble to set a hotkey just to have the program exit after it's been used once. without the "exit" code, the script is repeatable and you may continue to use the hotkey to activate the script. otherwise the hotkey just seems unneeded, if you could just run the script and exit when the code was finished.

I've added a section for if neither Online or Offline was found as sort of an error catch, which has the exit in there. Just a few thoughts.

Edited by FlashpointBlack

Share this post


Link to post
Share on other sites
NizonRox

Thx. Thats rly what i needed, ill be looking into it and return if i got another problem :)

Share this post


Link to post
Share on other sites
jdelaney

Rather than broadly looking for text, you should look for the div that holds the data, and get it's innertext...be sure that the text you are looking for is the actual expected state of your login.


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×