Code Script .co.uk

Home | Scripts | Tutorials | Disclaimer | Sitemap | Contact

   Get Html Tag Content
 

Vbscript / Text Processing / Get Html Tag Content

Function to find and return the text between two strings (beginning string and end string) in some text content. The character from which to start the search is specified for multiple uses of the function with the same content.



url="http://www.bbc.co.uk"

begStr = "<title>"
endStr = "</title>"

Set objHTTP = CreateObject("MSXML2.XMLHTTP")
Call objHTTP.Open("GET", url, FALSE)
objHTTP.Send

If NOT objHTTP.status = "200" Then
WScript.Echo "Check your URL. Request returned status: " & objHTTP.status
Wscript.Quit
End If

content = objHTTP.ResponseText

 
Wscript.Echo getTagContent(begStr,endStr,content,1)


'Get tag content function
Function getTagContent(begStr,endStr,content,beg)

begPt = inStr(beg, content, begStr) + Len(begStr) - 1
endPt = inStr(begPt, content, endStr) - 1

If (begPt = Len(begStr) - 1) OR (EndPt = -1) Then
tagCont = ""
pos = Len(content)
Else

pos = begPt

beghtml = Left(content,endPt)

tagCont = Right(beghtml, endPt - begPt)

End If

getTagContent = tagCont

End Function





Please note that a disclaimer applies to any code on this page.
 
   Actions
  Go Back
  Bookmark
  Print Page


   Menu
 
- Links
- Reference
- Script Editors
- Tutorials
- Vbscript
     - Active Directory
     - Exchange
     - Files And Folders
     - General
     - Ms Office
     - Operating System
     - Processes And Services
     - Text Processing
          - Filter Text Lines Containing
          - Get Html Tag Content
          - Merge File Contents
          - Read Xml File
     - User Interaction
     - Web Servers