Jump to content

Store text as a string help


Recommended Posts

Hello all. I'm new to Autoit and was hoping some kind sole might be able to help me. What I want to do is be able to select all the text on a given webpage and store it as a string. Then see if the word "total" is in the copied text, and if it is run a new explorer window. Here is how I am trying to do this.

CODE
$text = Send ( "^a^c" )

$compare = StringInStr ( "$text", "total", 0, 1 )

If $compare = 1 Then Run ( "explorer" , "" , @SW_MAXIMIZE )

I'm not storring the string right is my guess but I don't know how to display a stored string to see what it is. Is there a way I can open up Notepad.exe and paiste the copied string into it to check?

Thanks in advance for the help in advance:)

Link to comment
Share on other sites

Hello all. I'm new to Autoit and was hoping some kind sole might be able to help me. What I want to do is be able to select all the text on a given webpage and store it as a string. Then see if the word "total" is in the copied text, and if it is run a new explorer window. Here is how I am trying to do this.

CODE
$text = Send ( "^a^c" )

$compare = StringInStr ( "$text", "total", 0, 1 )

If $compare = 1 Then Run ( "explorer" , "" , @SW_MAXIMIZE )

I'm not storring the string right is my guess but I don't know how to display a stored string to see what it is. Is there a way I can open up Notepad.exe and paiste the copied string into it to check?

Thanks in advance for the help in advance:)

Assuming Send("^a^c") does what you want it doesn't return the copied text, it puts it in the clipboard. So to get the text you need Clipget.

Send ( "^a^c" )

$text = ClipGet()

The IE.AU3 udf might have better functions for this though.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

I now understand how to store it as a string thank you. Now I am having trouble searching the text to see if a word exists. I found this code snippet. If I'm not misstaken this will search for the string "211."

CODE
$sText = _IEBodyReadText($oIE)

If StringInStr($sText, "211") Then

;;; I found it

_IEAction($oIE, "refresh")

Else

;;; didn't find it

;;; do something else

EndIf

I don't understant what the "$oIE" constant is refering to. What would I use to have it read the body of the currently opened IE window?

Link to comment
Share on other sites

No, but you could try with _IEDocReadHTML

Here is the example script:

#include <IE.au3>
$oIE = _IE_Example ("basic")
$sHTML = _IEDocReadHTML ($oIE)
MsgBox(0, "Document Source", $sHTML)

And you could delete the msgbox and add like a check if the variable sHTML has the word "total" in it.

I do not have time to write how right now, but use the help file! :)

Good luck!

Link to comment
Share on other sites

I got it to scan the text of the window rather than the title using this.

CODE
$terms = "FooBar@gmail.com"

$sText = _IEBodyReadText($oIE)

If StringInStr($sText, $terms, 0) Then

;;; I found it

Send ( "{TAB}^C" )

Send ( "http://www.FooBar.com/ {ENTER}" )

WinWaitActive ( "", "Done" )

Sleep ( 800 )

MouseClick ( "Left", 700, 300, 1 )

Send ( "^v" )

;MouseClick ( "Right", 670, 395, 1 )

Else

;;; didn't find it

Send ( "{ALT}{LEFT}" )

Send ( "{TAB}{ENTER}" )

EndIf

I'm having trouble adding multiple keywords to search for in $term. I tried adding "Or" after "FooBar@gmail.com" but this didnt work. Would I need another If statement for this? Thanks for the help with this:)

Edited by darknezz19
Link to comment
Share on other sites

I am not sure what this program exacly does, as I am not home and I can't run the script, but for your multiple keywords I would add an loop:

$terms[2] = "FooBar@gmail.com", "BooBar@gmail.com;;writing the values to an array, change the arrays values ([2]) if you need more

$sText = _IEBodyReadText($oIE)

For $loop = 1 To $terms[0];;the loop start
If StringInStr($sText, $terms[$loop], 0) Then
;;; I found it
Send ( "{TAB}^C" )
Send ( "http://www.FooBar.com/ {ENTER}" )
WinWaitActive ( "", "Done" )
Sleep ( 800 )
MouseClick ( "Left", 700, 300, 1 )
Send ( "^v" )
;MouseClick ( "Right", 670, 395, 1 )
Next;;Keeps on repeating till end of keywords

Else
;;; didn't find it
Send ( "{ALT}{LEFT}" )
Send ( "{TAB}{ENTER}" )

Test this, change the other keyword to yours. But as I said I am not sure that this is a working code as I cant try it.

I hope it works.

PS: The array values maybe incorrectly inserted (check it in the help file) and it maybe 3 valöues now as maybe [0] is counted too, you must test.

Edited by LinuZ
Link to comment
Share on other sites

I tried to plug in my keywords but im getting errors about "$terms[2]" not being declared and also the loop needing an EndIf. I tried to add it myself at the end of the Else statement, but it was a no go. It's frustrating not knowing how to fix this yet.

Link to comment
Share on other sites

Ya, sorry, my fault, it was badly scripted, but to my favour I can say I hadnt SciTe when I wrote it :)

Try again:

Dim $terms[2]
$terms[0] = "FooBar@gmail.com"
$terms[1] = "BooBar@gmail.com";;writing the values to an array, change the arrays values ([2]) if you need more

$sText = _IEBodyReadText($oIE)

For $loop = 1 To $terms[0];;the loop start
If StringInStr($sText, $terms[$loop], 0) Then
;;; I found it
Send ( "{TAB}^C" )
Send ( "http://www.FooBar.com/ {ENTER}" )
WinWaitActive ( "", "Done" )
Sleep ( 800 )
MouseClick ( "Left", 700, 300, 1 )
Send ( "^v" )
;MouseClick ( "Right", 670, 395, 1 )

Else
;;; didn't find it
Send ( "{ALT}{LEFT}" )
Send ( "{TAB}{ENTER}" )
EndIf
Next;;Keeps on repeating till end of keywords

The $oIE variable isnt declared, but you maybe have it?

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...