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.
|