...

View Full Version : How retrieve a remote webpage?



JANLEE
10-01-2005, 02:45 AM
Hi,

I am using the below code, but I don't get retrieve the webpage in the screen:

It is my code:





<% Option Explicit %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
</head>

<body>
<form method=GET action="">
<input type="text" name="strLink">
<input type="submit" name="btnSubmit" value="Show">
</form>

<%
Dim show
if request.form("btnSubmit") = Show then
Dim strPage ' holds the page
Dim strDomain ' holds the domain
Dim objXmlHttp ' XML Http object
Dim strHTML ' holds the HTML code of the page
Dim strTitleLength ' holds the length of the title
Dim strBodyLength ' holds the length of the title
Dim strTitle ' holds the title of the page
Dim strStrip ' holds the parts between < >
Dim strWarning ' holds a warning when the page seems to be invalid

'enter the domain on which the page resides
strDomain = request.form("strLink")


' XML routine to get the file
Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
objXmlHttp.open "GET", strDomain, False
objXmlHttp.send
strHTML = objXmlHttp.responseText
Set objXmlHttp = Nothing

strTitleLength = CInt(instr(lcase(strHTML),"</title>"))-CInt(instr(lcase(strHTML),"<title>")+7)
strBodyLength = CInt(instr(lcase(strHTML),"</body>"))-CInt(instr(lcase(strHTML),"</head>")+7)

' determine whether the page has a valid title
if CInt(instr(lcase(strHTML),"</title>")) = 0 or CInt(instr(lcase(strHTML),"<title>")+7) = 7 then
strTitle = "No Title"
else
strTitle = Mid(strHTML,CInt(instr(lcase(strHTML),"<title>")+7),strTitleLength)
end if

' determine whether the page has a valid body
if CInt(instr(lcase(strHTML),"</body>")) = 0 or CInt(instr(lcase(strHTML),"</head>")+7) = 7 then
strWarning = 1
else
strHTML = Mid(strHTML,CInt(instr(lcase(strHTML),"</head>")+7),strBodyLength)
end if

' ******************** Do the actual stripping ********************
do while CInt(instr(strHTML,"<")) > 0 and CInt(instr(strHTML,">") + 1) > CInt(instr(strHTML,"<"))
strStrip = mid(strHTML,CInt(instr(strHTML,"<")),CInt(instr(strHTML,">") + 1)-CInt(instr(strHTML,"<")))
strHTML = replace(strHTML,strStrip,"")
loop
strHTML = Replace(strHTML, vbCrLf, "")
strHTML = replace(strHTML,"&nbsp;","")
strHTML = replace(strHTML,"<br>","")
Do While InStr(1, strHTML, " " ,vbTextCompare) > 0
strHTML = Replace(strHTML , " ", " ")
Loop
' ********************** The stripping ends **********************

' Give some output
response.write("<font face=""Verdana"" size=""2"" color=""#0000CC"">Title:</font><br>")
response.Write("<font face=""Verdana"" size=""2"" color=""#000000"">" & strTitle & "</font><br>")
response.write("<font face=""Verdana"" size=""2"" color=""#0000CC"">Text Output:</font><br>")
if strWarning = 1 then
response.Write("<font face=""Verdana"" size=""2"" color=""#FF0000"">This seems to be an invalid HTML-file!</font><br>")
end if
response.Write("<font face=""Verdana"" size=""2"" color=""#000000"">" & strHTML & "</font><br>")
end if
%>

</body>
</html>

I will be happy for any information.

Thanks

JLee

neocool00
10-03-2005, 07:51 PM
What's the error message you are getting? What url are you using?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum