Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find text in internet explorer window

Status
Not open for further replies.

jamesjames1

Technical User
Jun 18, 2004
81
GB
Hi,

I have created some code to output the contents of an Internet EXplorer Window. I need to be more detailed and find a string in the output. The problem I have is that the Inst functionappears to be ignored and the complete contents is displayed. Can I use Instr function, if so how???

stringy = Search
set ie = createobject("internetexplorer.application")
ie.navigate " do until ie.readystate = 4 : wscript.sleep 10: loop
if instr (ie.document.body.innerText,test) then

Wscript.echo ie.document.body.innerText


end if
ie.quit
 
instr tells you whether or not string1 appears in string2. It doesnt modify your strings

Code:
test="Bin Laden"
if instr (ie.document.body.innerText,test) then
 Wscript.echo "I have found " & test
else
 Wscript.echo test & " is missing"
end if
 
Thanks for that info. The instr statement is working so I am able to identify URL's for specific strings. I am having difficulty actually writing the data to a text file. If I run wscript.echo ie.document.body.innerText I can get a message box containing all the text.If I then try to write this to text file I get an invalid procedure call.

Reason I am writing to text file is because I can find a function to excho the line in "ie.document.body.innerText" which contains the string...

what am I missing here???

ta
 
you saying this doesnt work? or are you redirecting the stdout of the script to a file?

Code:
Dim str
str= ie.document.body.innerText
Set myFSO = CreateObject("Scripting.FileSystemObject")
Set f = myFSO.OpenTextFile("page.html", 8, True)
f.WriteLine(str)
f.Close
 
Hi Ya,

I have managed to get it working. Here is the code I have complied.

Dim str
Const ForReading = 1
ForWriting = 2
ForAppending = 8


test="Bin Laden"
set ie = createobject("internetexplorer.application")
ie.navigate " do until ie.readystate = 4 : wscript.sleep 10: loop
'if instr (ie.document.body.innerText,test) then

Wscript.echo ie.document.body.innerText


if instr (ie.document.body.innerText,test) <> 0 then
Wscript.echo "I have found " & test


abc= ie.document.body.innerText
Set myFSO = CreateObject("Scripting.FileSystemObject")
Set f = myFSO.OpenTextFile("c:\output.txt", ForAppending, True, -1)
f.WriteLine(abc)
f.Close



else
Wscript.echo test & " is missing"
end if


Take a look at this line of code:
Set f = myFSO.OpenTextFile("c:\output.txt", ForAppending, True, -1)

Note the -1 at the end. Found it in a forum and it basically adds a Unicode format designator and here is the link:
Thanks for your help, I hope you learnt as much as I did...
 
Note the -1 at the end. Found it in a forum and it basically adds a Unicode format designator

You would have also found it in the WSH documentation.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top