GetWebPage Function:
Returns the html source code of a specified web address.
Description:
The GetWebPage Function outputs the HTML source of a specified web address. The GetWebPage Function expects a valid web site address or URL as input, and the optional proper character set of the page. A list of character set can be found here: http://www.livio.net/main/charset.asp. GetWebPage uses the HTTP "GET" method via the XMLHTTP object to retrieve the page. GetWebPage returns empty string "" in the event of an error.
Syntax:
string = GetWebPage( HTTPAddress, CharSet )
Details:
Arguments: HTTPAddress = a valid web site URL address CharSet = the web site character set
Example:
<%
Dim strPage strPage = GetWebPage( "http://www.livio.net/main/default.asp", "" ) '--- get the html source of the livio.net home page and store it into the variable strPage.
Response.Write "<pre>" & server.htmlencode(GetWebPage("http://www.livio.net/main/default.asp", "")) & "</pre>" '--- display the html source of the livio.net home page.
%>
ASP Source Code:
<%
Private Function GetWebPage(ByVal HTTPAddress, ByVal CharSet) Dim strContent, xml_http, strBody, strText, max '--- Fetch the web page On error resume next Set xml_http = Server.CreateObject("Microsoft.XMLHTTP") xml_http.Open "GET", HTTPAddress, False xml_http.Send If Err Then GetWebPage = "" Exit Function End If strContent = xml_http.responseBody Set xml_http = Nothing On Error GoTo 0 '--- Converts the binary content to text '--- Create Stream object Dim BinaryStream Set BinaryStream = CreateObject("ADODB.Stream") '--- Specify stream type - we want To save text/string data. BinaryStream.Type = 1 '--- Open the stream And write text/string data To the object BinaryStream.Open BinaryStream.Write strContent '--- Change stream type To binary BinaryStream.Position = 0 BinaryStream.Type = 2 '--- Specify charset For the source text (unicode) data. If Len(CharSet) > 0 Then BinaryStream.CharSet = CharSet Else BinaryStream.CharSet = "UTF-8" End If '--- Open the stream And get binary data from the object strText = BinaryStream.ReadText '--- remove headers max = InStr(1, strText, Chr(10) & Chr(10), 1) GetWebPage = Mid(strText, max + 1) End Function
%>
|