WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE with MSIE
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Locate a String on a Webpage

 Keywords: Locate Search Find Text String Content URL Web Page Webpage Internet Explorer COM InternetExplorer.Application CreateTextRange Method Text Property

Question:

I really appreciate if you give me an example on how to search a string on a web page.

Answer:

Here is some code that should accomplish this:
;***************************************************************************
;**
;**  Locate a string on a webpage
;**
;***************************************************************************

objIE = ObjectCreate("InternetExplorer.Application")
objIE.visible = @FALSE
url = "http://www.winbatch.com"
objIE.navigate (url)

While objIE.busy || objIE.readystate <> 4
   TimeDelay(0.5)
EndWhile

objDoc = objIE.Document
objTextRange = objDoc.Body.CreateTextRange

; This contains the text content on the webpage
pagecontent = objTextRange.Text
; Message(url, pagecontent)

;Search for test in pagecontent using StrIndex or StrIndexNC
ptr = 1
While ptr != 0
   ptr = StrIndexNC(pagecontent, "winbatch", ptr, @FWDSCAN)
   If ptr == 0 Then Break
   Message("Found character position", ptr)
   ptr = ptr+1
EndWhile

objDoc = 0
objIE.Quit
objIE = 0
Exit

Article ID:   W18132
Filename:   Locate a String on a Webpage.txt
File Created: 2012:10:03:12:10:34
Last Updated: 2012:10:03:12:10:34