Sign in to follow this  
Followers 0
NSearch

IE.au3 count function

10 posts in this topic

I am working on a script that navigates to a webpage, enters some numbers, submit, and then depending on the response, take a certain action. I am wondering if there is a way to count the occurances of a word in the source code so that I could use some code like:

If $count_approval > 0 then

$message = "approved"

else

$message = "denied"

EndIf

I am trying to have this run completely in the background using IECreate(0), so opening up the source code, saving it, and then reading the file is not how I want to do it. (The way I am currently doing it)

Thanks.

Share this post


Link to post
Share on other sites



I am working on a script that navigates to a webpage, enters some numbers, submit, and then depending on the response, take a certain action. I am wondering if there is a way to count the occurances of a word in the source code so that I could use some code like:

If $count_approval > 0 then

$message = "approved"

else

$message = "denied"

EndIf

I am trying to have this run completely in the background using IECreate(0), so opening up the source code, saving it, and then reading the file is not how I want to do it. (The way I am currently doing it)

Thanks.

i was pretty sure there was a function to assign the source to a variable, but can't find it (looked for like 3 whole seconds - very short attention span) but anyway, you don't have to read line by line... if you have the source saved to a file, do this:

#include<array.au3>
$source = FileRead("c:\index.html",FileGetSize("C:\index.html"))
dim $count = _StringSubLoc($source,"whatever")

If $count[0] > 0 then
   $message = "approved"
else
  $message = "denied"
EndIf

Func _StringSubLoc($ack, $blah)
    $bl = StringLen($blah)
    $al = StringLen($ack)
    Dim $occ[1]
    $occ[0] = 0
    If StringInStr($ack, $blah) Then
        For $x = 1 To $al - $bl
            If StringMid($ack, $x, $bl) = $blah Then
                $occ[0] = $occ[0] + 1
                _ArrayAdd($occ, $x + 1)
            EndIf
        Next
    Else
        Return (-1)
        Exit
    EndIf
    Return ($occ)
EndFunc  ;==>_StringSubLoc

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

I am working on a script that navigates to a webpage, enters some numbers, submit, and then depending on the response, take a certain action. I am wondering if there is a way to count the occurances of a word in the source code so that I could use some code like:

If $count_approval > 0 then

$message = "approved"

else

$message = "denied"

EndIf

I am trying to have this run completely in the background using IECreate(0), so opening up the source code, saving it, and then reading the file is not how I want to do it. (The way I am currently doing it)

Thanks.

Sure... check out _IEBodyReadHTML() to get the HTML from the body. Then StringReplace is the easies way to get a string match count that I know of:
SrtingReplace(_IEBodyReadHTML($oIE), "approved", "approved")
If @extended > 0 then
   $message = "approved"
else
  $message = "denied"
EndIf

Dale

p.s. _IEBodyReadHTML() uses $oIE.document.body.innerHTML to get the HTML code... if you just want to search the text you can use $oIE.document.body.innerText


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

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

i think you 1. want to continue with IE.au3 controls and two dont want to write a file

so... use this idea to search for your "word" within the body of the html code

#include <IE.au3>

$oIE = _IECreate()
_IENavigate($oIE, "http://www.autoitscript.com/")

$body = _IEBodyReadHTML($oIE)

If StringInStr($body, "automation") Then
    MsgBox(0, "Success", "The string was found")
    $newbody = StringReplace($body, "automation", "AUTOMATION - Yeah!")
    _IEBodyWriteHTML($oIE, $newbody)
Else
    MsgBox(0, "Fail", "The string was NOT found")
EndIf

Exit

Hope that helps

8)

oops.... mr Dale himself beat me to it...

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

Thanks cameronsdad. I used

$Message_Output = FileOpen("C:\Output.html",1)
    $message = _IEBodyReadHTML($oIE)
    FileWrite($Message_Output, $message & @CRLF)
    FileClose($Message_Output)
    $source = FileRead("C:\Message_Output.html",FileGetSize("C:\Output.html"))
    dim $count = _StringSubLoc($source,"blah blah")
    If $count[0] > 0 then
        $message = "denied"
        MsgBox(0,"message1",$message)
    else
        $message = "approved"
        MsgBox(0,"message2",$message)
    EndIf
    FileDelete($Message_Output)

Share this post


Link to post
Share on other sites

Wow, you guys are quick! By the time I responded, two more posts were up! I am going to take a look, but I am well on my way to automating another project. Thank you so much.

Share this post


Link to post
Share on other sites

Sure... check out _IEBodyReadHTML() to get the HTML from the body. Then StringReplace is the easies way to get a string match count that I know of:

SrtingReplace(_IEBodyReadHTML($oIE), "approved", "approved")
If @extended > 0 then
   $message = "approved"
else
  $message = "denied"
EndIf

Dale

p.s. _IEBodyReadHTML() uses $oIE.document.body.innerHTML to get the HTML code... if you just want to search the text you can use $oIE.document.body.innerText

i knew there was a function, but i didn't see it immediately and knew right where i had my strings udf. Thanks Dale

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

Thanks cameronsdad. I used

$Message_Output = FileOpen("C:\Output.html",1)
    $message = _IEBodyReadHTML($oIE)
    FileWrite($Message_Output, $message & @CRLF)
    FileClose($Message_Output)
    $source = FileRead("C:\Message_Output.html",FileGetSize("C:\Output.html"))
    dim $count = _StringSubLoc($source,"blah blah")
    If $count[0] > 0 then
        $message = "denied"
        MsgBox(0,"message1",$message)
    else
        $message = "approved"
        MsgBox(0,"message2",$message)
    EndIf
    FileDelete($Message_Output)
glad i could help, and glad you had better luck locating the _IEBodyReadHTML than i did

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Pretty cool to see others jumping in so quickly on IE.au3 questions -- I think I'll hang back a bit because I might just learn something :-)

Dale

Edited by DaleHohm

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

Share this post


Link to post
Share on other sites

Pretty cool to see others jumping in so quickly on IE.au3 questions -- I think I'll hang back a bit because I might just learn something :-)

Dale

i doubt that... we can still learn alot from you

Internet Explorer Automation UDF library * 123» 18(pages)

prototype pre-release

269 (posts)

19508 (views )

Last post by: DaleHohm

really nice stuff Dale

8)


NEWHeader1.png

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  
Followers 0